Differences between HTML and XHTML

XHTML is HTML, but it requires that you follow the coding practices required of XML. Here are the differences:

  HTML XHTML
Case Sensitive No Yes
Permits Unclosed Elements Yes No
Permits Overlapping Elements Yes No

Here some examples:

<p>Some text</P> is possible in HTML, but not in XHTML because the capitalisation is inconsistent. In XHTML<p> and <P> are considered separate elements.

In HTML a line break is created with <br>. In XHTML, the element must be closed with a slash: <br />.

In HTML, it is possible to have code like <p><b>Some text</p></b>. In XHTML, this overlapping code is not allowed; it should read <p><b>Some text</b></p>.

Which Should I Choose?

In most cases, XHTML is a better choice because it creates more consistent coding which will be more compatible with methods of data processing in the future (in case you hadn't noticed, HTML allows you to be somewhat sloppy).

For information on how to indicate which flavour of (X)HTML you are using, see the page on Good Practices - The DTD and character set <meta>.

Why does the browser display my page correctly, even though I have not consistently coded in XHTML?

In short, you're lucky. The browser designers anticipated that people would be sloppy and built in safeguards. But this isn't something you should count on, as not all browsers are the same. It can also lead you to develop some bad habits. Why not just do it right? You can check that you have conformed to the standards for either HTML or XHTML by validating your web page. For information on how to validate, see the page on Good Practices - The DTD and character set <meta>.

 

Return to Top