XHTML
On this page, you will find what is XHTML, read about its specificities, benefits and the main differences between XHTML and HTML/HTML5.
XHTML (Extensible HyperText Markup Language), developed by the World Wide Web Consortium (W3C) in 2000, is an extended version of the popular HTML. It is the same HTML but defined as an XML application, which combines the advantages of both HTML and XML.
XHTML retains all the features of HTML but introduces stricter rules for creating pages, which allows you to make sites independent of the display device and browser. It means that the site will be correctly displayed in all modern browsers and platforms like computers, smartphones, PDAs, etc.
XHTML is supported by all modern browsers.
Difference between HTML and XHTML
-
You should always use
<!DOCTYPE ....>. An XHTML document must include an XHTML Doctype Declaration. Other required elements are the<html>,<head>,<title>, and<body>tags.Example of XHTML Document With Required Elements:
XHTML vs HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Title of the document</title>
</head>
<body>
Content of the page
</body>
</html>- You should insert XHTML elements properly. In an XHTML document, you cannot nest elements improperly. It should look like this:
XHTML nesting elements
<strong>
<em>This text is bold and italic</em>
</strong>- Unlike HTML, where we can sometimes omit the closing tag, in XHTML the closing tag is required always and everywhere:
XHTML closing tags
A break: <br/>
A horizontal rule: <hr/>
An image: <img src="smile.gif" alt="Always smile" />- Lowercase and uppercase tags are distinguished in XHTML. To avoid confusion, all tags, as well as their attributes must be typed in lowercase:
XHTML lowercase tags
<body>
<p>Some paragraph</p>
</body>- You must write XHTML attributes in lower case, like this:
XHTML lowercase attributes
<table width="100%">- You must put the attribute values in quotes, like this:
XHTML attribute values in quotes
<table width="100%">- You cannot minimize attributes. The abbreviated attribute is not assigned a value. An attribute can be assigned an attribute value that matches the name. It shouldn’t look like this:
XHTML attribute assignment
<input type="checkbox" name="flower" value="rose" checked />Instead, it must look like this:
XHTML attribute assignment example
<input type="checkbox" name="flower" value="rose" checked="checked" />- It is better to use the
idattribute instead ofname. In XHTML thenameattribute is partially obsolete, so it’s recommended to use theidattribute.
Benefits of XHTML
- The fact that in XHTML all tags must be closed and nested correctly makes the code look much cleaner.
- XHTML uses less bandwidth, which reduces cost especially if your site has thousands of pages.
- Thanks to being well-formed, XHTML documents are easily transported to wireless devices, Braille readers and other specialized web environments.
- XHTML works with CSS to create web pages easily.
XHTML vs HTML
HTML is the main markup language for creating web pages, while XHTML, as mentioned above, is the extended version of it. HTML is an application of Standard Generalized Markup Language (SGML), while XHTML is an application of XML. HTML is extended from SGML, and XHTML from XML and HTML. HTML was created by Tim Berners-Lee in 1987(Wikipedia)and XHTML was proposed by World Wide Consortium in 2000 (Wikipedia). And the last difference between these two is the flexible framework requiring lenient HTML specific parser in case of HTML and restrictive subset of XML which needs to be parsed with standard XML parser in case of XHTML.
XHTML vs HTML5
XHTML is case sensitive, while HTML5, as well as HTML, are not. XHTML has much more complex doctypes than HTML5. The next difference is browser compatibility: HTML5 is supported by all modern browsers, while XHTML is also supported but requires proper MIME type configuration (application/xhtml+xml) to be parsed strictly. HTML5 is the modern standard for all devices, whereas XHTML is largely considered legacy. And one more difference is that HTML5 is more lenient than XHTML.
Practice
What are some characteristics of XHTML (Extensible Hypertext Markup Language)?