Last Updated: 21 Nov 2020


Author: (external edit)

HTML vs. XHTML - Which One to Choose

There is much debate over whether HTML or XHTML is the 'better' way to write code. First some background reading:

I won't rehash the historical reasoning (see those blog posts), but basically, it comes down to this:

  • Almost all documents on the web are served with content type text/html by apache, IIS, etc, regardless of whether they are XHTML or HTML. This is because IE (apparently including IE 7) doesn't handle documents with content type application/xhtml+xml, offering them up for download instead of viewing.
  • Because the content type determines how a document is parsed, all documents are parsed as HTML (even if they have an XHTML doctype or XHTML code).
  • Thus, the argument goes, if you send XHTML code, you're really sending invalid HTML code, which is more likely to break the HTML parser than proper HTML code. Therefore, just write valid, standards-compliant, HTML 4.01 code and you'll be better off.
  • The opposite argument notes that the W3C says that XHMTL 'MAY' be served as text/html (even if it isn't actually parsed as XML), and that XHTML (at least if it is fully valid XHTML) is cleaner, faster and more likely to be forward-compatible than standard HTML 'tag-soup'. Since browsers all interpret XHTML properly, send that instead.

In my opinion, it really doesn't matter that much. I use XHTML for some projects, standard HTML for others. In practice, there is very little difference. The biggest, most important thing is to make sure you use a STRICT doctype, and not one of the transitional ones.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">



As you can see on the Activating Browser Modes page, those two doctypes force standards mode rendering in as many browsers as possible. That's much more important than XHTML vs. HTML.


Enter your comment. Wiki syntax is allowed: