XHTML, the Extensible HyperText Markup Language, is a reformulation of HTML as an application of XML, which means every document must be well-formed XML before a browser or parser accepts it. It keeps the familiar vocabulary of HTML elements such as paragraphs, links, tables and forms, but replaces the forgiving parsing rules of classic web markup with the strict syntax of XML.
The W3C published XHTML 1.0 in 2000 as a bridge between the HTML 4.01 vocabulary and the wider XML ecosystem. Today the idea survives as the XML serialization of HTML5, sometimes called XHTML5, while most web pages use the ordinary HTML syntax. Understanding XHTML remains useful for EPUB publishing, XML toolchains and any system that must process web content with a standard XML parser.
How XHTML differs from classic HTML parsing
XHTML differs from classic HTML mainly in how strictly the document is parsed. An HTML parser follows error-recovery rules that silently repair unclosed tags, unquoted attributes and misnested elements, whereas an XML parser applies draconian error handling and stops at the first well-formedness error.
The practical consequence is that a single missing end tag can prevent an XHTML page from rendering at all when it is served as XML. Browsers display a parsing error message instead of the content, which makes XHTML predictable for machines but unforgiving for authors who edit pages by hand.
The following table summarizes the syntax rules that XHTML inherits from XML and how they contrast with the tolerant HTML syntax.
| Rule | XHTML requirement | HTML syntax behavior |
|---|---|---|
| Element closing | Every element must be closed | Some end tags are optional |
| Void elements | Self-closing form such as <br /> | Plain <br> is sufficient |
| Name case | Element and attribute names in lowercase | Names are case-insensitive |
| Attribute values | Always quoted | Quotes optional for simple values |
| Boolean attributes | Written as checked="checked" | Bare checked is allowed |
| Nesting | Strictly proper nesting | Misnesting repaired by the parser |
| Namespace | Root declares the XHTML namespace | No namespace declaration needed |
The XHTML namespace, http://www.w3.org/1999/xhtml, is declared on the root html element through the xmlns attribute. This declaration lets XML software recognize the elements as XHTML and allows other vocabularies such as SVG and MathML to be mixed into the same document.
Versions and document types of XHTML
XHTML evolved through several specifications, some of which were widely deployed and some of which never reached practical use. Each version defined its own document type declaration, the Doctype line that tells validators which rules apply.
| Version | Year | Purpose | Current status |
|---|---|---|---|
| XHTML 1.0 Strict | 2000 | HTML 4.01 vocabulary without presentational elements | Superseded |
| XHTML 1.0 Transitional | 2000 | Allowed legacy elements such as font | Superseded |
| XHTML 1.1 | 2001 | Modularized vocabulary, XML media type expected | Superseded |
| XHTML Basic | 2000-2008 | Subset for mobile devices | Obsolete |
| XHTML 2.0 | Drafts to 2009 | Incompatible redesign of the language | Abandoned |
| HTML5 XML syntax | 2014 onward | XML serialization of the living HTML standard | Active |
The abandonment of XHTML 2.0 in 2009 marked a turning point. Browser vendors, working through the WHATWG, favored an evolutionary HTML5 that kept backward compatibility with existing pages, and the W3C eventually aligned with that approach. XHTML did not disappear, however; it became one of two serializations of the same HTML document model.
Why the media type decides how XHTML is parsed
Whether a browser treats a page as XHTML depends on the MIME type sent by the server, not on the Doctype or the syntax inside the file. A document delivered as text/html goes through the HTML parser even if it is perfectly well-formed XHTML, so its XML properties are ignored.
Only the media type application/xhtml+xml triggers the XML parser in browsers. During the 2000s many sites wrote XHTML syntax but served it as text/html, because older versions of Internet Explorer could not render the XML media type. Such pages gained cleaner markup habits but none of the technical benefits of XML processing.
| Served media type | Parser used | Error handling | Typical use |
|---|---|---|---|
| text/html | HTML parser | Errors silently repaired | Ordinary websites |
| application/xhtml+xml | XML parser | Fatal error on malformed markup | XML-based publishing |
| application/xml | Generic XML parser | Fatal error, weaker semantics | Rare, tooling cases |
The XML parsing mode also changes some scripting and DOM behavior. For example, document.write() is not supported, element names in the DOM keep their lowercase form, and content inside script elements must be escaped or wrapped in a CDATA section when it contains characters such as < or &.
Where XHTML is still used today
XHTML remains relevant wherever machine processing matters more than tolerance. Its predictable structure lets standard XML tools such as XSLT, XPath and XQuery transform and query documents without a custom HTML parser.
- EPUB 3 e-books require content documents in the XHTML syntax of HTML5, so every chapter of a reflowable e-book is an XHTML file.
- Content management and documentation pipelines often store articles as XHTML so they can be validated and transformed with XSLT.
- Embedded and specialized user agents, including some e-readers and print formatters, rely on XML parsers for simplicity.
- Mixed-namespace documents combine XHTML with SVG, MathML or custom XML vocabularies in one file.
For general websites, the HTML syntax of HTML5 is the practical default. Developers who want strict, readable markup usually achieve it through HTML validation and linting tools rather than by switching to the XML media type.
Common mistakes when authoring XHTML
Most XHTML problems stem from confusing syntax with parsing mode or from habits carried over from tolerant HTML. The table below lists frequent symptoms, their causes and the correct fix.
| Symptom | Cause | Fix |
|---|---|---|
| Yellow XML error page | Unclosed or misnested element | Validate and close every element |
| Entity error on ` ` | Named entity unknown to the XML parser | Use a numeric reference or the character itself |
| Script fails to run | Unescaped < or & in inline script | Use a CDATA section or an external file |
| Styles ignored | Uppercase element names in markup | Write all names in lowercase |
| No XML behavior at all | Page served as text/html | Send application/xhtml+xml |
Another misconception is that XHTML is inherently faster or more semantic than HTML. The vocabulary and semantics are the same; the difference lies only in serialization and error handling, so semantic quality depends on the author choosing appropriate elements in either syntax.
In simple terms
XHTML is the same language used to build web pages, but written under much stricter grammar rules. Ordinary HTML is like a friendly editor who quietly fixes your typos. XHTML is like a strict examiner who refuses the whole page if a single tag is left open.
That strictness makes life harder for people typing pages by hand, but easier for computer programs that need to read, check and convert documents. This is why XHTML lives on mainly in e-books and publishing systems, while most websites use regular HTML.
A practical example
A small academic publisher converts a 300-page textbook into an EPUB 3 e-book. Each of the 24 chapters becomes a separate XHTML file with the XHTML namespace on the root element, lowercase tags and self-closing image elements, and mathematical formulas are embedded directly as MathML.
Before release, the production team runs an EPUB validator over the package. It reports two fatal errors: a paragraph closed in the wrong order around an emphasized phrase and an entity that the XML parser does not recognize. After the editor closes the elements correctly and replaces the entity with a numeric character reference, the book passes validation and displays consistently on e-readers. The result is a single well-formed source that the publisher also transforms with XSLT into print-ready output.