HTML - HTML vs. XHTML
Overview
Estimated time: 15–25 minutes
HTML5 is the living standard and is not XML. XHTML is HTML serialized as XML, with stricter rules.
Key Differences
- Parsing: HTML is parsed as HTML; XHTML must be well-formed XML.
- Case: XHTML tags/attributes should be lowercase; HTML is case-insensitive (conventionally lowercase).
- Self-closing: XHTML uses
<br />
; HTML uses<br>
. - Attribute quoting: Required in XHTML; recommended in HTML.
Examples
<!-- HTML5 -->
<img src="x.png" alt="">
<!-- XHTML -->
<img src="x.png" alt="" />
Common Pitfalls
- Serving XHTML as text/html—browsers treat it as HTML, not XML.