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.
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:
|
<!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:
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:
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:
Why 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 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 |
Similar Reads
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 in
5 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
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
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
What is DTD in XML ? DTD is a document-type definition. DTD contains a set of rules that control the structure and elements of XML files. When any XML file refers DTD file, it validates against those rules. DTD has validated elements and attributes that are defined inside the DTD document. It serves as a formal specific
3 min read
How to parse XML in Ruby? XML - Extensible Markup Language is used format on the platform for exchanging data and storing data on the web. Ruby, consists of a huge number of libraries and its syntax is flexible does provides several methods for parsing XML documents easily. In this article, we will look into various methods
2 min read
How to Read XML File in R? XML (Extensible Markup Language) can be a widely used format for storing and transporting data. It can be structured and allowing the both humans and machines to easily parse and interpret the data it contains. In R programming, reading and processing XML files is straightforward thanks to the vario
5 min read