Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • HTML Tutorial
  • HTML Exercises
  • HTML Tags
  • HTML Attributes
  • Global Attributes
  • Event Attributes
  • HTML Interview Questions
  • HTML DOM
  • DOM Audio/Video
  • HTML 5
  • HTML Examples
  • Color Picker
  • A to Z Guide
  • HTML Formatter
Open In App
Next Article:
WML | Introduction
Next article icon

XHTML Introduction

Last Updated : 10 Jan, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

XHTML or EXtensible HyperText Markup Language is a mix of HTML and XML, very similar to HTML but stricter. It’s like a rulebook for creating web pages that browsers easily understand. Unlike HTML, you have to be careful and follow the rules exactly. Most browsers support it. Just think of it as a more precise way to write web code.

Table of Content

  • History
  • Transitional DTD
  • Strict DTD
  • Frameset DTD
  • Why use XHTML?
  • Benefits of XHTML
  • Difference Between HTML and XHTML

History

It was developed by the World Wide Web Consortium (W3C) and helps web developers transition from HTML to XML. With XHTML, developers can enter the XML world with all its features while still ensuring backward and future compatibility of the content. The XHTML family includes three document types; the first is XHTML 1.0, which was recommended by W3C on January 26, 2000. The second is XHTML 1.1, which was recommended by W3C on May 31, 2001.

The third is XHTML5, a standard used for developing an XML adaptation of the HTML5 specification. An XHTML document must have an XHTML <!DOCTYPE> declaration.

Elements of XHTML:

XHTML Element Description
<!DOCTYPE> Used to declare the Document Type Definition (DTD), specifying the rules for the markup language, ensuring proper rendering in browsers.
<html> Encloses the entire HTML or XHTML document, serving as the root element.
<head> Contains meta-information about the document, such as the title, character set, linked stylesheets, and other essential elements.
<title> Nested within the head section, specifies the title of the document, displayed in the browser’s title bar or tab.
<body> Encloses the content of the web page, including text, images, links, and other HTML elements. It represents the visible part of the document displayed in the browser.

When creating an XHTML web page, it is necessary to include a DTD (Document Type Definition) declaration. There are three types of DTD which are discussed below:

Transitional DTD:

It is supported by the older browsers which do not have inbuilt cascading style sheets supports. Several attributes are enclosed in the body tag which are not allowed in strict DTD. 

Syntax:

<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

Example: In this example we will see the code for writing an XHTML document with an example. 

html




<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 
<head>
    <title>Transitional DTD XHTML</title>
</head>
 
<body bgcolor="#dae1ed">
    <div style="color:#090;font-size:40px;
                font-weight:bold;text-align:center;
                margin-bottom:-25px;">GeeksforGeeks</div>
    <p style="text-align:center;font-size:20px;">
        A computer science portal</p>
    <p style="text-align:center;font-size:20px;">
        Option to choose month:
        <select name="month">
            <option selected="selected">January</option>
            <option>February</option>
            <option>March</option>
            <option>April</option>
            <option>May</option>
            <option>June</option>
            <option>July</option>
            <option>Augusy</option>
            <option>September</option>
            <option>October</option>
            <option>November</option>
            <option>December</option>
        </select>
    </p>
</body>
 
</html>
 
 

Output:

transitional dtd xhtml 

Strict DTD:

Strict DTD is used when XHTML page contains only markup language. Strict DTD is used together with cascading style sheets, because this attribute does not allow CSS property in body tag. 

Syntax:

<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

Example 2: In this example we will see the code for writing an XHTML document with an example for strict DTD. 

html




<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 
<head>
    <title>Strict DTD XHTML</title>
</head>
 
<body>
    <div style="color:#090;font-size:40px;
                font-weight:bold;text-align:center;
                margin-bottom:-25px;">GeeksforGeeks</div>
    <p style="text-align:center;font-size:20px;">
        A computer science portal</p>
    <p style="text-align:center;font-size:20px;">
        Option to choose month:
        <select name="month">
            <option selected="selected">January</option>
            <option>February</option>
            <option>March</option>
            <option>April</option>
            <option>May</option>
            <option>June</option>
            <option>July</option>
            <option>Augusy</option>
            <option>September</option>
            <option>October</option>
            <option>November</option>
            <option>December</option>
        </select>
    </p>
</body>
 
</html>
 
 

Output:

 strict dtd xhtml 

Frameset DTD:

The frameset DTD is used when XHTML page contains frames. This DTD is identical to the HTML 4.01 Transitional DTD except for the content model of the HTML element.

Syntax:

<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
"DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">


Example 2: In this example we will see the code for writing an XHTML document with an example for frameset DTD.

html




<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xml:lang="en" lang="en">
 
<head>
    <title>Frameset DTD XHTML</title>
</head>
<frameset cols="30%, 20%, *">
    <frameset rows="40%, 30%, *">
        <frame src="gfg.html" />
        <frame src="gfg1.html" />
        <frame src="geeks.html" />
    </frameset>
    <frameset rows="40%, 60%">
        <frame src="g4g.html" />
        <frame src="g4g1.html" />
    </frameset>
    <frameset rows="20%, 20%, 30%, *">
        <frame src="geeksforgeeks.html" />
        <frame src="geeksforgeeks1.html" />
        <frame src="geeksforgeeks2.html" />
        <frame src="geeksforgeeks3.html" />
    </frameset>
</frameset>
 
</html>
 
 

Output:

frameset dtd xhtmlWhy use XHTML?

  • XHTML documents are validated with standard XML tools.
  • It is easily to maintain, convert, edit document in the long run.
  • It is used to define the quality standard of web pages.
  • XHTML is an official standard of the W3C, your website becomes more compatible and accurate with many browsers.

Benefits of XHTML:

  • All XHTML tags must have closing tags and are nested correctly. This generates cleaner code.
  • XHTML documents are lean which means they use less bandwidth. This reduces cost particularly if your web site has 1000s of pages.
  • XHTML documents are well formatted well–formed and can easily be transported to wireless devices, Braille readers and other specialized web environments.
  • All new developments will be in XML (of which XHTML is an application).
  • XHTML works in association with CSS to create web pages that can easily be updated.

Difference Between HTML and XHTML:

HTML XHTML
HTML or HyperText Markup Language is the main markup language for creating web pages XHTML (Extensible HyperText Markup Language) is a family of XML markup languages that mirror or extend versions of the widely used Hypertext Markup Language (HTML)
Flexible framework requiring lenient HTML specific parser Restrictive subset of XML which needs to be parsed with standard XML parsers
Proposed by Tim Berners-Lee in 1987 World Wide Web Consortium Recommendation in 2000.
Application of Standard Generalized Markup Language (SGML). Application of XML
Extended from SGML. Extended from XML, HTML


Next Article
WML | Introduction

A

Ayusharma0698
Improve
Article Tags :
  • HTML
  • HTML and XML

Similar Reads

  • WML | Introduction
    WML stands for Wireless Markup Language (WML) which is based on HTML and HDML. It is specified as an XML document type. It is a markup language used to develop websites for mobile phones. While designing with WML, constraints of wireless devices such as small display screens, limited memory, low ban
    6 min read
  • Introduction to XPath
    XPath(XML Path) is an expression that is used to find the element or say node in the XML document. In Selenium it is commonly used to find the web elements. What is XPath?XPath stands for XML Path Language. It's an expression language that is used to query or transform. We use it to traverse among e
    3 min read
  • HTML5 MathML Introduction
    Mathematical Markup Language (MathML) is an XML-based markup language designed to represent mathematical expressions and formulas on web pages. It is an integral part of HTML5, allowing browsers to display mathematical content without the need for additional plugins or images. Importance of MathML i
    6 min read
  • AIML Introduction
    AIML (Artificial Intelligence Markup Language) is a description language used in the development of natural language software agents like chatbots and virtual assistants. AIML was developed by Richard Wallace from 1995 to 2000, and it is based on XML (eXtensible Markup Language). AIML provides autom
    4 min read
  • XPath Injection
    Injection attacks are the most well-known attacks used by hackers to inject code or malware into programs or to query a computer to run remote commands that can read or modify a database or modify data on a website. XPath is a query language that helps by providing relative information on how to fin
    5 min read
  • XML declarations
    An XML declaration is a statement placed at the beginning of an XML document that provides essential information about the document's encoding, version, and standalone status. It serves as a metadata header and helps parsers and processors understand how to interpret the XML content correctly. Synta
    3 min read
  • XML - CDATA Sections
    CDATA sections are a mechanism in XML for handling character data that might otherwise be misinterpreted by the XML parser. CDATA stands for Character Data. These sections include blocks of text within an XML document that the parser should treat literally, without interpreting any characters as XML
    2 min read
  • HTML Description Lists
    An HTML Description List is not as commonly used as unordered or ordered lists but serves an important purpose for displaying name-value pairs. This type of list is marked up using three tags: <dl>, <dt>, and <dd>. <dl> (Description List): This tag defines the description lis
    3 min read
  • XML Tutorial
    XML, or Extensible Markup Language, is a way to structure and organize information in a text format that is easy for computers to read. It uses tags, similar to those in HTML, to define different types of data inside a document. XML allows data to be stored and shared in a consistent and structured
    4 min read
  • Pretty Printing XML in Python
    XML stands for Extensible Markup Language and is used to encode a document that can be understandable by both humans and machines. Data stored in XML format is easy to understand and easy to modify. There are three main things that have to keep in mind when you are using XML – Simplicity, Generality
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences