Is XHTML worthwhile?

Let’s me nail my colours to the mast straight away: I use XHTML and have done so for several years. XHTML 1.0 has been a W3C recommendation for seven years (since January 2000). I’m aware of the well-argued objections by Ian Hixie, among others, against sending XHTML as text/html. Opponents of switching to XHTML 1.0 also point out quite rightly that XHTML 2.0 won’t be backwards compatible with previous versions.

So the arguments that break out in online forums from time to time about whether to use XHTML always tend to go over the same ground again and again: XHTML 1.0 isn’t really XHTML because it’s normally delivered using the wrong MIME type (text/html instead of application/xhtml+xml), and anyway everything’s going to change several years down the line when XHTML becomes the standard. My viewpoint has always been this:

  • XHTML 1.0 is an official standard
  • It’s fully supported by modern browsers (even Netscape 4 has no problems with it)
  • Using XHTML 1.0 properly (in other words, making sure that it validates) teaches you the stricter standards that will be necessary when XHTML 2.0 eventually comes along (if it ever does)
  • Well-formed XHTML makes it easier to work with CSS and dynamic code, such as PHP

Of course, you could use the same arguments about valid HTML 4.01. What matters most of all is that your code follows the rules and doesn’t rely on the forgiving nature of current browsers to cover up your mistakes.

This subject came up again a few days ago in the Dreamweaver forum. The discussion didn’t produce any real enlightenment, but it set me thinking. One of the arguments used in the past against adopting XHTML 1.0 is that “it doesn’t futureproof your site” because you’ll have to do everything again when XHTML 2.0 comes along. Then it struck me: that argument is completely wrong.

XHTML 1.0 is HTML 4.01 reformulated as XML. Since XML is designed to be machine-readable, it is futureproof. Pages designed with XHTML 1.0 may not be displayed by future browsers in the same way as XHTML 2.0, but the DOCTYPE will tell the XML parser how to read it. The same isn’t be true of HTML pages, even if they validate according to the 4.01 recommendation, because an XML parser will choke on empty elements, such as img tags.

This entry was posted in Dreamweaver, General, PHP. Bookmark the permalink.

6 Responses to Is XHTML worthwhile?

  1. Browsers serve html whether it be xhtml served as text/html or plain html 4.01 and while that is the case I will continue to use html 4.01, strict of course !
    I don’t buy the fact that just using xhtml makes you a more efficient coder as the transitional doctype still allows deprecated elements like target blank and border=”0″ on images for instance example page. Being efficient is separating content and presentation and the only real way to do this in my humble opinion is to use a strict doctype of whatever flavour of html you decide to use.

  2. David says:

    Dave, you have missed my point. Arguments about deprecated elements are meaningless. XHTML is XML, whereas HTML is not. This means that a page written in HTML 4.01 will always require an HTML-compatible browser. However, as long as a page is written in well-formed XHTML, it can be parsed by anything capable of reading XML.

    Since XML doesn’t define the meaning or purpose of any tag or attribute, it doesn’t matter if you use deprecated attributes in an XHTML document. Of course, deprecated attributes may not be supported by future browsers, but they remain perfectly valid as XML. The key point is that the document can still be parsed correctly, whereas an HTML document cannot.

  3. Andrew Ingram says:

    Also, XSLT will probably be an option for converting XHTML1 to XHTML2 so the conversion process for any major sites wouldn’t be that big a problem.

  4. David, my point perhaps made poorly is that when served as text/html xhtml is served as html not xml and until the worlds most popular browser stops choking on documents served as xml I cannot see any benefit in xhtml for me or my clients.

  5. Caroline Schnapp says:

    Dave, you live in the present (“until the world’s most popular”). David thinks about the present AND the future.

    Things change so fast. Impact of this is that computer books I buy one year are usually useless the next.

    Since IE7 is out, most of the content of a recently published book such as CSS Mastery is… well, not so useful anymore (sort of an understatement). CSS Mastery provides solutions that bend backwards to accomodate the “present”, the non-standard-compliant browser IE. Now that IE 7 is out, and that it supports PNG… (for example), and that people are forced to update to IE 7, and that it is impossible to download and install IE 6 now, then the whole chapter on images and drop shadows in CSS Mastery is… useless in that book. Same with the hack and filter chapter. If you are able now to do what it takes to accomodate both the present and the future, then the smart move is to do just that.

    I came to the web fairly late in my life. I came from the world of C++ (as an engineer). I did not have to un-learn habits… I find XHTML easy, consistent, and I just… use it. Why use HTML when you can use XHTML ? (refering to David’s argument, with whom I agree on this matter).

  6. Nathan McCance says:

    Caroline,

    I have to say that CSS Mastery is far from being obsolete. IE7 is not very standards compliant (yes, they support PNG now, but that has nothing to do with CSS). Their support for CSS barely reaches the CSS 1.0 standard. I still run into a considerable number of problems with IE7 on a number of issues. And to say that the techniques of the book are obsolete when many people won’t upgrade to IE7 (I know quite a few people who never update their computers using Windows Update) is silly.

    Backwards compatibility is still the name of the game when it comes to designing web pages.