Why use XHTML

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

Why use XHTML

XHTML was developed to make HTML more extensible and increase interoperability with other data formats. There are two main reasons behind the creation of XHTML:

  • It creates a stricter standard for making web pages, reducing incompatibilities between browsers. So it is compatible for all major browsers.

  • It creates a standard that can be used on a variety of different devices without changes.

Let's take an example to understand it.

HTML is mainly used to create web pages but we can see that many pages on the internet contain "bad" HTML (not follow the HTML rule).

For example:

  1. <html>  
  2. <head>  
  3.   <title>This is an example of bad HTML</title>  
  4. <body>  
  5.   <h1>Bad HTML  
  6.   <p>This is a paragraph  
  7. </body>  

This HTML code works fine in most browsers (even if it does not follow the HTML rules).

The above HTML code doesn't follow the HTML rule although it runs. Now a day, there are different browser technologies. Some browsers run on computers, and some browsers run on mobile phones or other small devices. The main issue with the bad HTML is that it can't be interpreted by smaller devices.

So, XHTML is introduced to combine the strengths of HTML and XML.

XHTML is HTML redesigned as XML. It helps you to create better formatted code on your site.

XHTML doesn't facilitate you to make badly formed code to be XHTML compatible. Unlike with HTML (where simple errors (like missing out a closing tag) are ignored by the browser), XHTML code must be exactly how it is specified to be.