Right, if this thread is going to be sticky, I'll add another thing that seems to confuse many beginners.
What is required for a document to be treated like XHTML?
- A content type that says it's an application of XML.
- An XML namespace equal to 'http://www.w3.org/1999/xhtml'.
The content type (a.k.a. media type or MIME type) must be sent by the server in the Content-Type HTTP header. You cannot change the content type with a META element, since the user agent needs to know what the document is before starting to parse it. There are three MIME types that will do this for XHTML:
Using text/xml is not recommended, because there are some serious encoding issues with that MIME type. The recommended one is application/xhtml+xml.
Arguably, the server should not send any character encoding information in the Content-Type header, since X(HT)ML is meant to be a self-describing format where the encoding should be specified in the XML declaration. Thus the server should only send this:
and the document should start with something like this:
<?xml version="1.0" encoding="utf-8"?>
Note that if you use a MIME type of text/xml, the encoding will be US-ASCII unless the server sends encoding information in the Content-Type header. You cannot override it with an XML declaration (and, of course, not with a silly <meta/> element).
The content type only tells the user agent that the document is an application of XML. Even if the MIME type is application/xhtml+xml, user agents don't know that it is, in fact, XHTML.
The thing that tells them that is the 'xmlns' attribute of the document's root element:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
If you don't use this exact namespace URI, the document is not an XHTML document; it's general XML. That will cause some interesting effects in how the page is rendered... It will also cause certain elements to stop working, because the semantics is lost.
What about DOCTYPE?
Didn't I forget something in my list above? Surely, it's the doctype declaration that makes it XHTML? This techie stuff about HTTP headers and XML namespaces is just a smoke screen, isn't it? 'Fraid not.
The doctype declaration doesn't matter at all, as far as browsers are concerned. Browsers that support XHTML will not do doctype switching when the document is served as an application of XML. At least not to my knowledge. They will use their strict rendering mode.
The doctype is only used when you're validating your document. A validator must know with which flavour of XHTML you're claiming compliance. Browsers don't care.