Stop Using XHTML!

June 13, 2008 / The case for avoiding XHTML unless you are really serious about the ‘Xtensible’ part.

Four years back Anne van Kesteren wrote a little piece on why you should use HTML instead of XHTML unless you are going to serve the latter with the right MIME type (application/xhtml+xml), arguing that even then it’s only really useful if you’re planning on mixing in markup from other XML namespaces, like MathML and SVG. It is XML, after all. Eight months earlier Mark Pilgrim made a similar argument in a hypothetical piece about what might happen if more sites actually did serve XHTML with the correct MIME type. Both are great articles if you like writing that combines heavy debunking and markup languages. It’s a powerful genre.

Anyway, I mention all this to make a similar point to the one in my previous post: if you can use HTML (over XHTML), then it’s probably the best idea. XHTML served as text/html (e.g. what WordPress produces) doesn’t hurt anything, and will not be worth changing for most people. But XHTML served this way is being treated as HTML (not as an XML subset) by the browser, so if nothing else you’re sending more cruft in the head than you need to, and you’re not getting the XML treatment for your pages that you thought you were:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
<html xmlns="">
    <meta http-equiv="Content-Type" content="text/html; 
        charset=UTF-8" />
    <title>Page title</title>

If you enjoy life with the W3C validator, then go with HTML 4.01 (use the “strict” doctype to trigger the browser layout engine’s Standards mode) and stick to the familiar XHTML 1.0 element restrictions to keep with the standards-based approach (e.g. no font tags!). Henri Sivonen explains the value of this approach on the Mozilla Web Author FAQ with typical brevity:

Serving valid HTML 4.01 as text/html ensures the widest browser and search engine support.

I prefer using HTML5 over 4.01 and I use Sivonen’s conformance checker instead of the W3C validator for these pages—it’s really fast too. And there are some sweet new elements coming when browser support catches up, such as section, header, footer, nav, article, figure, audio, video… the list goes on. A HTML5 document starts out something like this, short and sweet:

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <title>Page title</title>

Don’t get me wrong: I like using XHTML and I think that it’s done huge things for the visibility of web standards and for accessibility by associating a leaner, more semantic approach to markup with the use of CSS for presentation. But HTML5 is, for a lot of designers and developers, a logical step right now from XHTML 1.0, especially those who like typing out all their pages from scratch :-)

2 responses

  1. Dean Edridge

    HTML5 is actually HTML and XHTML
    There are two languages that share the same vocabulary.
    When a web page is served using the text/html mime type it is called HTML5
    When a web page is served using the application/xhtml+xml mime type XHTML5

    June 13th, 2008 at 5:03 am #

  2. Ads

    Well, I suppose a more accurate title would have been “Stop using XHTML with text/html.” But since Internet Explorer 6 and 7 don’t support application/xhtml+xml, I’m saying it’s better for a majority of authors to stick with HTML.

    June 13th, 2008 at 8:49 am #

Zero to One-Eighty contains writing on design, opinion, stories and technology.