KillerSites Blog

Tag Soup: why using XHTML does not make sense.

February 5, 2005

Using XHTML instead of HTML to build web pages is one of today’s web design fads. Like other silly practices promoted by the web standards zealots (using CSS hacks for example,) this is something that will create extra work for no real PRACTICAL advantage and may even create problems for you!

People have been sold on XHTML with the typical web standards arguments that have a tendency to ignore the ‘reality in the field’. In this article I explain why you should stick to using good old HTML for the time being.

First, what is the reality today?

  1. Internet Explorer 6 and 7 (among other browsers,) will NOT render XHTML.
  2. If you use XHTML, DOM scripting and AJAX will be much more trouble.
  3. The supposed advantage (if ever realized,) are really minor at best.

Let’s consider these points:

BROWSERS AND XHTML

  • When you serve XHTML to most browsers, your crazy-cool XHTML will be treated like ordinary HTML, thus loosing all the supposed advantages of XHTML.
  • If you want browsers to treat XHTML as XHTML, you need to set the MIME type to: application/xhtm+xml. The problem is that IE6, IE7 and other browsers, will give you the ‘download this document’ pop-up box instead of displaying the page in the browser window.
  • If you’re really intent on using XHTML, you could use scripting to sniff out browsers and change the MIME type accordingly, but this would lead to script-branching – if you wanted to use any DOM / AJAX scripts … more headaches.

HOW DOM SCRIPTING IS MADE HARDER WITH XHTML

The issue that stands out the most for me (and is enough for me to not use XHTML,) is that you can’t use ‘document.createElement’ to create new elements with the DOM if you are using XHTML.

In case you don’t know, ‘document.createElement’ is one of the key methods of DOM programming and by extension AJAX.

This topic was recenty discused on the message board:

XHTML OR HTML

Stefan Mischook