Serving HTML5 as
application/xhtml+xml is quite simple, though there are some gotchas you need to know before doing so. The first thing to do is to set an XML prolog before the HTML5 DOCTYPE, thus providing also the default character encoding of the entire document. Since all XHTML documents have also a
meta tag that tells the validator what kind of content type they're going to handle, most developers will try to set this kind of tag in the
head section of their documents. Unfortunately, this will return a validation error.
There's no need to set this kind of tag. To pass validation, you have to follow two approaches:
- if you're serving a static file with a file extension (such as
xhtml), you don't need this tag
- if you're serving a dynamic document, just set the appropriate HTTP header before returning any output.
Finally, you have to set the XHTML namespace on the root element, which is
http://www.w3.org/1999/xhtml. A basic HTML5 template served as
application/xhtml+xml is shown below.