Search code examples
htmlcssxhtml

What's the need for XHTML?


In an interview I was asked a question that I'd never thought about, which was "We already have HTML which fulfills all the requirements of writing a web page, so what's the need for XHTML?"

I Googled a lot and also read many articles, but I'm not able to get properly why XHTML has been introduced. Please explain to me.


Solution

  • I am actually writing this to ask why the above three posts which speak about browser-consistence and well formed html have been voted down?

    As it is known HTML is a industry standard. Browsers are implemented so that they render the marked up content as described in the HTML standard. Unfortunately there are areas that have not been well defined in HTML: what happens if user forgot a closing tag or what to do if a referred image is not found? some browsers use the 'alt' tag to have a place holder text item and some browsers display the 'alt' tag as a tool tip. The famous 'quirks' mode of browsers is a result of this lack of clarity. Because of this, it became quite possible that the same web page would display differently on different browsers.

    Also as HTML usage grew there was one more problem: it was not extensible - there was no way to add user-defined tags.

    XHTML solves the above problems:

    • adopt XML to provide extensible tags.
    • provide a 'strict' standard for web browsers

    XHTML has well defined rules about the structure and these can be programatically enforced. Check the various online "XHTML Validators". They will tell if your XHTML is well formed or not (and highlight the problem areas). Because of these strict rules your page is more or less guaranteed to look the same on all browsers implementing XHTML.

    [note] if you want to verify the above, please refer to the text "Head First XHTML and CSS"