XHTML ( EXtensible HyperText Markup Language), developed by World Wide Consortium (W3C) in 2000, is the more 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 introduced more strict 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 ....>
Example of XHTML Document With Required Elements:¶Try it Yourself »
<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:
<strong> <em>This text is bold and italic</strong> </em>
- Unlike HTML, where we can sometimes omit the closing tag, in XHTML the closing tag is required always and everywhere:
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:
<body> <p>Some paragraph</p> </body>
- You must write XHTML attributes in lower case, like this:
- You must put the attribute values in quotes, like this:
- 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:
<input type="checkbox" name="flower" value="rose" checked />
Instead, it must look like this:
<input type="checkbox" name="flower" value="rose" checked="checked" />
- Instead of the name attribute you’ve better use id. In XHTML the name is partially obsolete, that’s why it’s recommended to use id attribute.
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 the browser, while XHTML is not. HTML5 is better suited for mobile devices, whereas XHTML is better suited for computer screens. And one more difference is that HTML5 is more lenient that XHTML.