HTML vs XHTML

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.

HTML vs XHTML 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.
Recommended: <b><span>DotNetTutorials</span></b>
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.

Recommended
Paragraph:<p>Paragraph</p>
Break: <br />
Horizontal rule: <hr />
Image: <img src=”smiley.gif” alt=”smiley” />

Not Recommended
Paragraph:<p>Paragraph
Break: <br>
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.

Recommended
<body>
<p>Paragraph</p>
<a href=”https://dotnettutorials.net/”>DotNetTutorials</a>
</body>

Not Recommended
<BODY>
<P>Paragraph</P>
<a HREF=”https://dotnettutorials.net/”>DotNetTutorials</a>
</BODY>

XHTML Attribute Values Must be Quoted

The XHTML attribute values must be enclosed with quotation marks.

Recommended
<a href=”https://dotnettutorials.net/”>DotNetTutorials</a>

Not Recommended
<a href=https://dotnettutorials.net/>DotNetTutorials</a>

Difference between HTML & XHTML
  1. XHTML is case sensitive whereas HTML5 is not.
  2. 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.)
  3. HTML5 is browser-independent. XHTML, on the other hand, is browser-dependent.
  4. HTML5, as the successor to HTML, is far more flexible than XHTML.
  5. XHTML is more suitable for desktop computers, but HTML5 is better suited for mobile devices such as smartphones and tablets.

Difference between HTML & XHTML

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.

Leave a Reply

Your email address will not be published. Required fields are marked *