XHTML is HTML rewritten to follow strict XML syntax rules. Modern HTML5 is far more forgiving — you rarely need to write or think about XHTML today, but the comparison still comes up in interviews.
Key Syntax Differences
| Rule | HTML5 | XHTML |
|---|---|---|
| Tags must be lowercase | Not required | Required |
| All tags must be closed | Not required (e.g. <li> can be left open) | Required, including void tags: <br /> |
| Attribute values must be quoted | Not required | Required |
| One root element | Recommended, not enforced | Strictly enforced (XML rule) |
| Invalid markup handling | Browser tries to recover and render anyway | Parsing stops entirely — "yellow screen of death" |
Example — Valid in HTML5, Invalid in XHTML
<!-- Valid HTML5: unquoted attribute, unclosed li -->
<ul>
<li class=item>First
<li class=item>Second
</ul>
<!-- XHTML requires this instead -->
<ul>
<li class="item">First</li>
<li class="item">Second</li>
</ul>
Both examples render identically in a browser using HTML5 parsing rules — the second is simply the stricter, more disciplined way to write it, which is also just good practice regardless of which standard you're targeting.
Why This Matters Less Today
Almost no one authors XHTML anymore. HTML5 deliberately chose a forgiving parser over strict XML rules, because a single unclosed tag breaking an entire page (as XML parsing does) was considered too fragile for the open web. Still, writing HTML with XHTML-style discipline — lowercase tags, quoted attributes, closed elements — remains good practice and is what most style guides and linters enforce today.
Common Mistakes
- Believing XHTML is "more modern" than HTML5 — it's actually the older, now largely abandoned direction
- Writing self-closing syntax like
<br />in modern HTML thinking it's required — it's optional in HTML5, though harmless to include
Interview Relevance
Q: "What happens if there's a syntax error in HTML vs XHTML?" HTML5's parser recovers and keeps rendering; XHTML (parsed as XML) stops rendering the whole page. This distinction is the most commonly tested part of this topic.
Practice Question
Rewrite this HTML snippet to be XHTML-compliant: <img src=photo.jpg><br>