HTML5 v. XHTML5

HTML5 allows developers to code very loosely, making the HTML 4 loose doctype seem strict. To me, not closing tags, omitting tags, not quoting attributes, etc., makes me throw up a little bit in my mouth. Not a pretty picture? Well, I would argue, neither is loose code. In fact, this is a valid HTML5 document:

<!DOCTYPE HTML>
<meta charset=utf-8>
<title>Valid HTML5</title>
<p>Tweetable Web page</p>

No <head>, no <body>, yet still valid. If that is too verbose for you, even:

<!DOCTYPE HTML>
<title>Blank Document</title>

is a valid HTML5 document. All you need is a doctype and a title.

If you want to code HTML5 yet still use valid XML syntax and headers, and serve your document as XML, you’re coding XHTML5: it seems that ‘XHTML5’ has become an official name of HTML5 coded and served as XML, since the original term "Polyglot Markup" never took off.

XHTML5 is a document that conforms to both the HTML and XHTML syntax by using a common subset of both the HTML and XHTML. To code XHTML5 you need to:

  1. Use the HTML5 doctype
  2. Code in XHTML well-formed syntax
  3. Default XHTML namespace: <html xmlns="http://www.w3.org/1999/xhtml">
  4. A server that serves up files as XML MIME type application/xhtml+xml

An XHTML5 document can be served as either HTML or XHTML, depending on browser support and MIME type. It really only becomes XHTML5 document if it is served with the XML MIME type application/xhtml+xml . Otherwise, it is just really well coded HTML5

For a document to be XML, you need a server that serves up the file as XML MIME type: application/xhtml+xml. This MIME declaration is not visible in the source code. If you want to check how you file is served, check the HTTP Content-Type header. The XML MIME type is not yet supported by Internet Explorer, but IE can render XHTML documents.

A XHTML5 document looks like this:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-us">
  <head>
    <meta charset="UTF-8"/>
    <title>XHTML5</title>
  </head>
  <body>
    <p>put valid XHTML markup here</p>
  </body>
</html>

The XML declaration <?xml version=”1.0” encoding=”UTF-8”?> is not required if the default UTF-8 encoding is used. The meta charset is also not required, if your server is set up with the HTTP Content-Type header.

No, you don’t need to serve your files as XML. You don’t even need to include the XHTML namespace to code valid HTML5. If you do choose to markup your HTML5 as if you were coding XHTML, your HTML5 document will validate. This article provides a definition of what is XHTML5 versus what is HTML5 coded using XHTML syntax.

Published by

Estelle Weyl

My name is Estelle Weyl. I an open web evangelist and community engineer. I'm a consulting web developer, writing technical books with O'Reilly, running frontend workshops, and speaking about web development, performance, and other fun stuff all over the world. If you have any recommendations on topics for me to hit, please let me know via @estellevw.