XHTML is called as HTML written as XML.
What Is XHTML?
HTML paragraphs are getting defined using the <p> and </p> tag:
Why XHTML?
Many pages of the internet consists of "bad" HTML
This HTML code seems to work fine in most of the browsers (even if it is not follow the HTML rules):
<html>
<head>
<title>This is bad HTML</title>
<body>
<h1>Bad HTML
<p>This is a paragraph
</body>
The present market has many different browser technologies. Some browsers are running on computers, and some browsers are running on mobile phones or other small devices. Smaller devices are usually lacking the resources or power for interpreting "bad" markup.
XML is a known as a markup language where documents should be marked up correctly (be "well-formed").
If you want to learn more about XML, please have a look at our XML tutorial.
Combination of the strengths of HTML and XML, XHTML was developed.
XHTML can be called as HTML redesigned as XML.
The Most Important Differences from HTML:
<!DOCTYPE ....> Is Mandatory
An XHTML document should be having an XHTML DOCTYPE declaration.
A entire list of all the XHTML Doctypes are found in HTML Tags Reference.
The <html>, <head>, <title>, and <body> elements should also be present, and the xmlns attribute in <html> should indicate the xml namespace for the document.
This example illustrates an XHTML document which is having a minimum of required tags:
<!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 document</title>
</head>
<body>
some content
</body>
</html>
XHTML Elements Must Be Properly Nested
In HTML, some elements are improperly nested inside each other,similar to like this:
<b><i>This text is bold and italic</b></i>
In XHTML, all elements should be nested inside each other,similar to like this:
<b><i>This text is bold and italic</i></b>
XHTML Elements Must Always Be Closed
This is not correct:
<p>This is a paragraph
<p>This is another paragraph
This is correct:
<p>This is a paragraph</p>
<p>This is another paragraph</p>
Empty Elements Must Also Be Closed
This is not correct:
A break: <br>
A horizontal rule: <hr>
An image: <img src="happy.gif" alt="Happy face">
This is correct:
A break: <br />
A horizontal rule: <hr />
An image: <img src="happy.gif" alt="Happy face" />
XHTML Elements Must Be In Lower Case
This is not correct:
<BODY>
<P>This is a paragraph</P>
</BODY>
This is correct:
<body>
<p>This is a paragraph</p>
</body>
XHTML Attribute Names Must Be In Lower Case
This is not correct:
<table WIDTH="100%">
This is correct:
<table width="100%">
Attribute Values Must Be Quoted
This is not correct:
<table width=100%>
This is correct:
<table width="100%">
Attribute Minimization Is Forbidden
Not correct:
<input type="checkbox" name="vehicle" value="car" checked />
Correct:
<input type="checkbox" name="vehicle" value="car" checked="checked" />
Wrong:
<input type="text" name="lastname" disabled />
Correct:
<input type="text" name="lastname" disabled="disabled" />
How to Convert from HTML to XHTML
HTML paragraphs will be defined using the <p> and </p> tag: