HTML vs XHTML with Examples
In this article, I am going to discuss HTML vs XHTML with Examples. Please read our previous article where we discussed HTML URL Encoding with Examples.
What is HTML?
HTML is an abbreviation for Hypertext Markup language. In 1991, Tim Berners-Lee invented HTML. It is the most common markup language for creating web applications. HTML is a very simple language to understand and easy to learn, made up of various elements which can be applied to normal words to give them special meanings. HTML is the most basic part of web application development.
What is XHTML?
XHTML is an abbreviation for Extensible Hypertext Markup Language. XHTML contains features of both XML and HTM, it can be considered a subset of the XML markup language. XHTML is a combination of XML and HTML. XHTML can be considered as a more advanced form of HTML.
<!DOCTYPE> is Compulsory
The <!DOCTYPE> declaration, as well as <html>, <head>, <title>, and <body> elements, are required in an XHTML document. The xmlns attribute in <html> must provide the document’s xml namespace. Here’s an example of a simple XHTML document:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Title of document</title> </head> <body> Content </body> </html>
XHTML Elements Must be Properly Nested
The elements should be properly nested.
Not Recommended: <b><span>DotNetTutorials</b></span>
XHTML Elements Must Always be Closed
All XHTML elements, including empty tags, should be closed with a closing tag.
Break: <br />
Horizontal rule: <hr />
Image: <img src=”smiley.gif” alt=”smiley” />
Horizontal rule: <hr>
Image: <img src=”smiley.gif” alt=”smiley” >
XHTML Elements and Attributes Must be in Lowercase
Lowercase must be used for all XHTML elements and attributes.
XHTML Attribute Values Must be Quoted
The XHTML attribute values must be enclosed with quotation marks.
Difference between HTML & XHTML
- XHTML is case sensitive whereas HTML5 is not.
- Both XHTML and HTML have a more complicated doctype than HTML5. (It’s important to note that doctype instructs browsers on how to read the data.)
- HTML5 is browser-independent. XHTML, on the other hand, is browser-dependent.
- HTML5, as the successor to HTML, is far more flexible than XHTML.
- XHTML is more suitable for desktop computers, but HTML5 is better suited for mobile devices such as smartphones and tablets.
In the next article, I am going to discuss Emojis in HTML with examples. Here, in this article, I try to explain HTML vs XHTML with Examples and I hope you enjoy this HTML vs XHTML with Examples article.