Skip to: content, navigation

by Tommy Olsson and Paul O’Brien

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

ID:
#4
Date:
Sun, 23 Dec 2007 11:41:50 GMT
Contributed by:
JochenVandeVelde
Status:
This note has not yet been confirmed for accuracy and relevance.

It should be noted that Internet Explorer doesn't accept documents served as application/xhtml+xml

ID:
#3
Date:
Wed, 19 Dec 2007 08:16:21 GMT
Contributed by:
AutisticCuckoo
Status:
This note has not yet been confirmed for accuracy and relevance.

This is a CSS reference, and it's not within its scope to explain the differences between HTML and XHTML is all detail. I wanted to point out that there are some differences in how CSS relates to the markup. That explanation requires a bit of understanding of some concepts, such as MIME types.

XHTML as text/html is totally pointless from a technical point of view, but as long as it complies with Appendix C it's not really harmful. If you want to use any XHTML 'features', you must serve it as an application of XML. It's that simple.

ID:
#2
Date:
Sat, 15 Dec 2007 12:49:58 GMT
Contributed by:
ennostuurman

I support the remark of workingtraffic, since the doctype/mime-type issue is in my opinion too easily disregarded. Different Sitepoint publications also use or recommend different doctypes depending on the mainpurpose of the page (be it heavy Javascripted or not, be it XML based or not etc..). I.e.: Stuart Langridge's DHTML Utopia comments in 'Whither XHTML' in which he refers to the 'tag soup' article at (www.hixie.ch/advocacy/xhtml)or Matthew Eernisse (Build your own AJAX web aplications) who advocates XHTML with a Mime-type of text/html.

ID:
#1
Date:
Mon, 10 Dec 2007 20:45:45 GMT
Contributed by:
workingtraffic

All very nice but I woudl like to know what the suggested best practice is. Examples are always good, how about a complete exampel header(s) and when to use each one and it's specific variations of content types and doctypes.

Hope that is helpfull feedback?

Add a note

To post a note on this topic, please log in with your SitePoint username and password. If you don't have an account yet, you can create a new account for free.

Related Products

The Principles of Beautiful Web Design

Best Seller!

You don’t need to go to Art School to design great looking web sites!

Book Cover: The Principles of Beautiful Web Design

Download the FREE sample chapters