HTML vs XHTML
XHTML
XHTML stands for Extensible Hypertext Markup Language. It can be considered as a
part of the XML markup language this is because of XHTML have features of both XML
and HTML. XHTML is extended from XML and HTML. XHTML can be considered as a
better version of HTML.
❖ XHTML is a stricter, more XML-based version of HTML.
HTML
HTML is the Hypertext Markup Language which is the most widely used language over
the internet. HTML is used to create web pages and link them from one to another.
Please note HTML is not a programming language. It is a markup language. We can use
different other technologies like CSS and javascript to give a new look to the pages
developed by HTML.
Differences from HTML
● <!DOCTYPE> is mandatory
● The xmlns attribute in <html> is mandatory
● <html>, <head>, <title>, and <body> are mandatory
● Elements must always be properly nested
● Elements must always be closed
● Elements must always be in lowercase
● Attribute names must always be in lowercase
● Attribute values must always be quoted
● Attribute minimization is forbidden
1
< !DOCTYPE > Is Mandatory
The DOCTYPE in XHTML is different from HTML , it must have an XHTML <!DOCTYPE>
declaration.
The <html>, <head>, <title>, and <body> elements are mandatory , and the xmlns
attribute in <html> must specify the xml namespace for the document.
Example : <!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"DTD/xhtml1-transitional.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
XHTML elements must be properly nested.
Correct : <div> <p> Coding Ninjas ! </p> </div>
Wrong : <div> <p> Coding Ninjas ! </div> </p>
XHTML Elements Must Always be Closed
Correct : <p> Paragraph 1 </p>
<p> Paragraph 2 </p>
Wrong : <p> Paragraph 1
<p> Paragraph 2
2
XHTML Empty Elements Must Always be Closed
Self closing tags must always be closed in XHTML.
Correct : Break Line <br />
<img src = " img.jpg " />
Wrong : Break Line <br>
<img src = " img.jpg " >
XHTML Attribute Names Must be in Lowercase
In XHTML, attribute names must always be in lowercase.
Correct : <a href = "https://www.codingninjas.com/"> Coding Ninjas ! </a>
Wrong : <a HREF = "https://www.codingninjas.com/"> Coding Ninjas ! </a>
XHTML Attribute Values Must be Quoted
In XHTML, attribute values must always be quoted.
Correct : <a href = "https://www.codingninjas.com/"> Coding Ninjas ! </a>
Wrong : <a HREF = https://www.codingninjas.com/> Coding Ninjas ! </a>