Elementary Standards
HTMLCSSWeb StandardsSEOBlogStart reading
Home / HTML / HTML and XHTML Are Identical in HTML5
HTML

HTML and XHTML Are Identical in HTML5

Two serializations, one DOM: what XHTML5 really is and when to reach for it.

6 min read·HTML

There is a persistent belief that XHTML died with the Web 2.0 era, tossed out along with rounded-corner gradients. Not quite. What died was XHTML as a religion. The living standard quietly kept the good part: HTML5 defines two ways to write the same language, and they parse into the exact same DOM tree.

<article>Read on</article>

Same tree, two syntaxes

A document is not the text you typed — it is the DOM the browser builds from that text. HTML5 specifies two serializations that produce an equivalent tree:

Once parsed, a <p> is a <p>. Your JavaScript, your CSS, your accessibility tree — all identical. The difference is entirely at the front door, in how the bytes become nodes.

The rules diverge only in strictness

In the HTML serialization, all of this is legal and common:

<ul>
  <li>First
  <li>Second
</ul>
<img src="cat.png">
<br>

The XML serialization forgives nothing. Every element closes, void elements self-close, attributes are quoted, and case matters:

<ul>
  <li>First</li>
  <li>Second</li>
</ul>
<img src="cat.png" />
<br />

The unforgiving part: draconian error handling

This is the crux of the decision. If an HTML document has a mistake, the browser silently repairs it and shows your page. If an XHTML document served as real XML has a single unclosed tag, the browser shows a yellow screen of death and renders nothing.

XML is honest to a fault. It would rather show you an error than a lie. Whether that is a feature or a landmine depends entirely on your build pipeline.

So which do you pick?

For nearly every website, choose the HTML serialization. It is robust against the small mistakes that inevitably reach production, it is what every CMS and templating engine emits, and the tooling is universal. The .xhtml extension or wrong MIME type is a classic way to break a site with no visible cause.

Reach for XHTML5 deliberately when you need it: documents assembled by XML toolchains, content that must round-trip through XSLT or XPath, or pipelines where strict well-formedness is a guarantee you actually want enforced. Just remember one trap — the MIME type is what decides the mode, not the syntax. Writing self-closing tags while serving text/html gives you HTML parsing with a cosmetic slash that the parser ignores. It is not XHTML; it is HTML in a costume.

More on HTML
Keep reading

Related essays