Q&A
XHTML vs HTML5
Overview
XHTML (2000s) was intended to push the web toward XML strictness and extensibility. In practice, browsers never enforced XML parsing on XHTML served as text/html, and the strictness created more friction than benefit. HTML5 (standardized in 2014, but in use much earlier) took the opposite approach: a realistic, error-tolerant standard built around what browsers actually do, while adding powerful new capabilities.
graph LR
A[XHTML] --> B["XML-strict syntax<br/>Must close all tags<br/>Lowercase only<br/>Served as text/html or application/xhtml+xml"]
C[HTML5] --> D["Forgiving parser<br/>Optional closing tags<br/>New semantics & APIs<br/>Living standard"]
B -.deprecated.-> D
style C fill:#1e1b4b,color:#fff
Key Differences
| Feature | XHTML | HTML5 |
|---|---|---|
| Based on | XML | SGML-derived, own parsing model |
| Parser strictness | Strict - one error stops rendering | Forgiving - error recovery built in |
| Tag case | Lowercase required (<html>, not <HTML>) |
Case-insensitive (lowercase convention) |
| Closing tags | All tags must be closed; void tags <br/> |
Void tags don't need / - <br> is fine |
| Attribute quoting | All attributes must be quoted | Unquoted attributes allowed (not recommended) |
| Self-closing | <br /> with space-slash |
<br> (slash optional for void elements) |
| DOCTYPE | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML ..."> |
<!DOCTYPE html> (simple) |
| Served as | text/html or application/xhtml+xml |
text/html |
| Semantic elements | None added | <header>, <nav>, <article>, <section>, <main>, <footer>, etc. |
| Multimedia | Plugins (Flash) | Native <audio>, <video>, <canvas> |
| APIs | None | Geolocation, Web Workers, WebSockets, localStorage, etc. |
| Status | Deprecated (XHTML 2.0 abandoned in 2009) | Current living standard |
XHTML Example
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>XHTML Page</title>
</head>
<body>
<p>Hello <br /> world.</p> <!-- self-closing void tag required -->
<img src="logo.png" alt="Logo" /> <!-- always closed -->
</body>
</html>
HTML5 Equivalent
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HTML5 Page</title>
</head>
<body>
<header>
<nav><a href="/">Home</a></nav>
</header>
<main>
<article>
<p>Hello <br> world.</p>
</article>
</main>
<footer>© 2026</footer>
</body>
</html>
Simpler DOCTYPE, shorter meta charset, semantic elements, void tags without closing slash.
HTML5's Key Additions Beyond XHTML
- Semantic structure:
<header>,<footer>,<main>,<nav>,<article>,<section>,<aside>,<figure>. - Forms: new input types (
email,date,range,search), validation attributes. - Media:
<audio>,<video>with native controls, no plugin needed. - Graphics:
<canvas>(2D/WebGL), inline SVG. - APIs:
localStorage/sessionStorage, Web Workers, WebSockets, Geolocation, History API, Fetch. - Accessibility: ARIA landmark roles baked in,
<details>/<summary>, etc.
Why XHTML Didn't Win
XHTML required XML-valid documents - one parsing error could break the entire page (when served as application/xhtml+xml). Real-world HTML on the internet was full of errors, and browsers (serving under text/html) silently recovered. The XML-strict vision was impractical for the messy web. The WHATWG's HTML5 spec embraced error recovery, compatibility, and new features - and it won.
Why This Matters in Interviews
Front-end interviews use this to test web standards history. Key points: XHTML = HTML as XML (strict, deprecated); HTML5 = forgiving, living standard, adds semantics and APIs. Know the practical differences (self-closing tags, DOCTYPE, case sensitivity), and be able to articulate why HTML5 is what you use today. Mentioning <!DOCTYPE html> as the simplest DOCTYPE and listing a few HTML5 semantic/API additions shows currency.
Common Pitfalls
- Thinking HTML5 requires XHTML-style self-closing syntax (it doesn't;
<br>is valid). - Using the XHTML long DOCTYPE form in new projects (just use
<!DOCTYPE html>). - Assuming XHTML strictness improves SEO or performance (no evidence; it just breaks things).
- Conflating "HTML5" with just new media/API features (it's the whole modern standard).
References
- HTML Living Standard: https://html.spec.whatwg.org/
- MDN HTML5: https://developer.mozilla.org/en-US/docs/Web/HTML