HTML5: XFBML validates only if served as application/xhtml+xml

Good news sometimes are bad news. While trying to validate an HTML5 document with XFBML embedded in it, I found out that you need to serve your documents as application/xhtml+xml to pass the W3C validation.

The reason is pretty simple: the XFBML namespace in use is invalid in a normal HTML5 document. That's because a namespace cannot be used in normal text/html documents but has a reason to exist in (X)HTML documents, that is, HTML5 documents which make use of the XHTML namespace. In XML-based documents namespaces are accepted because you're actually using XML as a base and in XML you can use namespaces.

So if you add xmlns="http://www.w3.org/1999/xhtml" to your html root element and the add also the XFBML namespace, your markup will be valid only if your document is served as application/xhtml+xml. Otherwise, it won't pass the validation.

Back to top