Difference between HTML and XHTML and their Uses

XHTML is an acronym of Extensive HyperText Markup Language. It is more strict than ordinary HTML. It is defined as XML application and also supported in all major browsers.

Why we need XHTML above HTML?

Many pages contain bad HTML. Even this HTML code has break the HTML rules, it works well in most browsers. Globally, people use more number of handset than computer and tablet. If we have multiple bad HTML elements within a page, smaller devices like smartphone get lack the power to interpret the bad markups.

How to convert HTML into XHTML?

1. Add <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> to the first line of every page.
2. Add an xmlns attribute (<html xmlns= "http://www.w3.org/1999/xhtml"> ) to the html element of every page.
3. Close all HTML empty tags.
4. Convert all element names into lowercase.
5. Quotes all attribute values.

Require and minimum elements to define an XHTML document

<!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>Name of the Title </title>
</head>
<body>
      Body content
</body>
</html>

Difference between HTML and XHTML

1. In XHTML, the <!DOCTYPE. . . > declaration is mandatory and also <html> (with xmlns attribute), <head>, <title> and <body< elements are all required while in an <html> document, <!DOCTYPE html> declaration is sufficient and all the attributes of <html> start tag are optional.
2. In XHTML, the elements must be properly nested.
In XHTML, the elements must be nested properly like

<b> <i> This text is bold and italic. </i> </b>

In HTML, the elements might be nested improperly like

<b> <i> This text is bold and italic. </b> </i>

3. In XHTML, all elements including empty elements must be properly closed.
In XHTML, all the following lines are false:

<p> This is a paragraph.
<p> This is also a paragraph.
An image: <img src="demo.gif" alt="demo">
Horizontal rule: <hr>
A Break: <br>

Inorder to make them valid syntax, we must them as follows

<p> This is a paragraph </p>
<p> This is also a paragraph </p>
An image: <img src="demo.gif" alt="demo" />
Horizontal rule: <hr />
A Break: <br />

4. XHTML elements and attributes must be defined in Lower Case.
In XHTML, it is false the following form:

<P> This is a paragraph </P>
<p ALIGN="center"> This is also a paragraph </p>

True Example in XHTML

<p> This is a paragraph </p>
<p align="center"> This is also a paragraph </p>

5. In XHTML, all the attributes must be quoted.
In XHTML, it is false the following form:

<p align= center> This is center alignment paragraph </p>

True Example in XHTML:

<p align= "center"> This is center alignment paragraph </p>

6. In XHTML, many attribute minimizations are forbidden.
In XHTML, the following minimizations are false.

<textarea readonly>
<textarea disabled>

True Example

<textarea readonly="readonly">
<textarea disabled="disabled">


If you are newbie to HTML, don't cross over to XHTML because it has more difficult from HTML and if any single error found on your xml document, the overall document results might not found on the web-browsers.