Skip to main content

XHTML versus HTML

Short answer

XHTML is a stricter, XML-based reformulation of HTML. It requires lowercase tags, closed elements, quoted attributes, proper nesting, and a mandatory DOCTYPE, whereas HTML is more forgiving, allowing optional tags and case-insensitivity.

How is XHTML different from HTML?

HTML (HyperText Markup Language) is the standard language for web pages and has loose syntax rules. XHTML (Extensible HTML) is HTML reformulated as an XML application, so it must follow XML's strict rules.

BasisHTMLXHTML
Based onSGMLXML
Tag caseCase-insensitive (<P> = <p>)Tags and attributes must be lowercase
Closing tagsSome may be omitted (<p>, <li>)Every element must be closed
Empty elements<br>, <img ...><br />, <img ... />
NestingWrong nesting often toleratedMust be properly nested
Attribute valuesQuotes optionalMust be quoted: width="100"
Attribute minimisation<input checked> allowedchecked="checked" required
Root element<html> optional in practice<html xmlns="http://www.w3.org/1999/xhtml"> required
DOCTYPEOptional/relaxedMandatory
Error handlingBrowser forgives errorsParser stops on a well-formedness error
MIME typetext/htmlapplication/xhtml+xml (or text/html)
ParsingNot XML-parsableCan be processed by XML tools

Example:

<!-- HTML -->
<p>First<br>
<input type=text name=a>

<!-- XHTML -->
<p>First<br />
<input type="text" name="a" /></p>

XHTML therefore gives cleaner, well-formed, more portable code, but HTML5 later became the main standard because it is more forgiving.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Web Technology chapter 2 questions →