XHTML applied XML rules to HTML vocabulary: well-formedness, lowercase conventions, explicit namespaces. Served as application/xhtml+xml, parsing stopped on the first fatal error.
Modern HTML
- Living standard parsed as HTML with defined error recovery.
- Singular
<!DOCTYPE html>. - Optional trailing slashes tolerated but unnecessary.
Why history matters
Enterprise CMS templates may still emit polyglot markup—know whether your pipeline expects XML tooling.
SVG/MathML integration
Foreign content embedded in HTML follows distinct parsing rules—validate integrated snippets separately.
Takeaway
Author forgiving HTML5 documents; reserve XML serialization for feeds or APIs that mandate strict XML.
When XHTML habits hurt
- Self-closing void tags in HTML5 are tolerated but unnecessary—don’t assume XML pipelines will ingest them unchanged.
- Case sensitivity in SVG attributes embedded inline still trips authors—validate integrated snippets.
Quick comparison
| Topic | HTML5 (text/html) | XHTML (XML) |
|---|---|---|
| Parsing errors | Recovered; DOM still built | Fatal—document may not render |
<br> closing | Optional / | Often written <br /> |
| Case | Tag names case-insensitive | Case-sensitive XML rules |
Polyglot snippet (only when you must)
<!-- XML tooling may require explicit closes on void elements -->
<meta charset="utf-8" />
<img src="logo.png" alt="Logo" width="120" height="40" />
Rendered output (HTML parser still accepts this style)
Polyglot-style trailing slashes are tolerated in HTML5, but modern teams usually standardize on plain HTML syntax.
Important interview questions and answers
- Q: What is the safest default character encoding for modern HTML?
A: UTF-8, declared early with `` and matched by server `Content-Type` headers. - Q: When are HTML entities still useful in UTF-8 pages?
A: For reserved characters (`&`, `<`) and contexts where explicit escaping avoids parser ambiguity. - Q: What is the key difference between HTML5 parsing and XHTML parsing?
A: HTML5 recovers from many errors; XHTML (XML) treats many parse errors as fatal.
Tip: HTML5 is the living standard; XHTML syntax rules are rarely required today.