Sending XHTML as text/html Considered Harmful -*- Mode: text; -*- ============================================= Author: Ian Hickson (Comments welcome.) Abstract -------- A number of problems resulting from the use of the text/html MIME type in conjunction with XHTML content are discussed. It is suggested that XHTML delivered as text/html is broken and XHTML delivered as text/xml is risky, so authors intending their work for public consumption should stick to HTML 4.01, and authors who wish to use XHTML should deliver their markup as application/xhtml+xml. Context ------- This was originally written in September 2002 in the context of this Web log entry: http://ln.hixie.ch/?start=1031465247&count=1 It has since been regularly updated to correct errors that have been brought up in various mailing lists and other discussion forums. As of late 2004, it is still just as relevant as when it was originally written. Note that this document compares XHTML 1.0 compliant to appendix C to HTML 4.01, because that is the only variant of XHTML that may be sent as text/html. Executive Summary ----------------- If you use XHTML, you should deliver it with the application/xhtml+xml MIME type. If you do not do so, you should use HTML4 instead of XHTML. The alternative, using XHTML but delivering it as text/html, causes numerous problems that are outlined below. Unfortunately, IE6 does not support application/xhtml+xml (in fact, it does not support XHTML at all). Why using text/html for XHTML is bad ------------------------------------ What usually happens to authors who decide to send XHTML as text/html is the following: 1. Authors write XHTML that makes assumptions that are only valid for tag soup or HTML4 UAs, and not XHTML UAs, and send it as text/html. (The common assumptions are listed below.) 2. Authors find everything works fine. 3. Time passes. 4. Author decides to send the same content as application/xhtml+xml, because it is, after all, XHTML. 5. Author finds site breaks horribly. (See below for a list of reasons why.) 6. Author blames XHTML. Steps 1 to 5 have been seen by every single person I have spoken to who has switched to using the XHTML MIME type. The only reason step 6 didn't happen in those cases is that they were advanced authors who understood how to fix their content. SPECIFIC PROBLEMS These are the issues that affect documents when they are switched from text/html to application/xhtml+xml: * To embed CSS in an XHTML document which may be handled as either HTML4 or XHTML, you have to use: Yes, it's pretty ridiculous. If documents _aren't_ escaped like this, then the contents of