MIME Types

When a web document is requested, the web server delivers an HTTP response comprising two parts: the headers and the body. The headers contain meta information about the body, while the body is the actual document (the HTML or XHTML markup, in this case).

One very important HTTP header is called Content-Type. This header specifies the MIME type, and though it can also contain information about the character encoding that’s used in the file, this data shouldn’t be included for XML documents. The MIME type tells the user agent what type of content it’s about to receive.

A Content-Type header for an HTML document can look like this:

Content-Type: text/html; charset=utf-8

For an XHTML document, it should look like this:

Content-Type: application/xhtml+xml

It’s primarily the MIME type that dictates how a web document’s handled by a browser. For an XML MIME type, the <html> tag’s xmlns attribute is what specifies a document as containing XHTML. The doctype declaration has nothing to do with this matter, except when it comes to validating the markup.

Internet Explorer doesn’t support the MIME type application/xhtml+xml. Although it supports application/xml and text/xml, it’ll treat the document as generic XML rather than XHTML. This is why most authors serve their XHTML markup as text/html, yet few realize that this causes browsers to handle their pages as HTML, rather than XHTML.

Serving XHTML as text/html is permitted by the W3C, provided that the markup complies with the guidelines in Appendix C of the XHTML 1.0 specification.

User-contributed notes

Related Products