Comparison
XML vs HTML
They look alike and behave in opposite ways: HTML forgives everything, XML forgives nothing. Feeding one to the other's parser is the most common way this bites.
HTML has a specified error-recovery algorithm — a browser handed broken markup must produce a tree anyway, and every browser produces the same one. XML has the opposite requirement: a well-formedness error is fatal, and a conforming parser must stop rather than guess.
That single difference explains the rest. HTML has void elements you never close, optional end tags, unquoted attribute values and boolean attributes. All four are well-formedness errors in XML, and a template that emits HTML habits into an XML document produces a file no parser will read.
XHTML was the attempt to have both, and it lost — but the XHTML namespace is still how a sitemap declares hreflang alternates, so you will meet it whether or not you ever write a page in it.
What actually differs
| Aspect | XML | HTML |
|---|---|---|
| On a syntax error | Fatal. The parser stops | Recovers, with a specified algorithm |
| Void elements | None. <br> must be <br/> | <br>, <img>, <meta> are never closed |
| End tags | Always required | Optional for many elements |
| Attribute quoting | Required | Optional in many cases |
| Boolean attributes | Not permitted — every attribute has a value | Permitted: <input disabled> |
| Case | Sensitive | Tag and attribute names are not |
| Vocabulary | Whatever you define | Fixed by the HTML specification |
Shown, not asserted
The differences above are claims, so here they are being made. Every one of these runs on each test run, against the same engines the tools use — the outputs are what came back, not what we expected.
An unclosed <br> — perfectly ordinary HTML — makes the whole document unreadable as XML.
document.xml <p>line one<br>line two</p>What came back
Opening and ending tag mismatch: br line 1 and p (line 1)Self-closed, the same markup is fine. That slash is the entire difference.
document.xml <p>line one<br/>line two</p>What came back
Well-formed. XML accepts it.So is an unquoted attribute value, which HTML permits and XML does not.
document.xml <img width=100/>What came back
AttValue: " or ' expected (line 1)
Which to pick
XML, when
- The consumer is a machine and you would rather it refuse bad input than guess at it.
- You need your own vocabulary, or someone else's — a feed, an invoice, a schema.
- The data is going to be validated, transformed, or signed.
HTML, when
- The consumer is a browser rendering a page for a person.
- Robustness matters more than strictness: a broken tag should degrade rather than blank the page.
Where it reaches
- Parse errorsOpening and ending tag mismatchThe message an unclosed void element produces.
- Parse errorsAttributes construct error (unterminated quote)And the one an unquoted attribute value produces.
- NamespacesXHTMLWhere the two meet, and why a sitemap declares it.
- ToolsXML validatorTells you which of the two you are actually holding.
Related comparisons
- XML vs JSONJSON won the API era and XML still runs the documents. The difference that decides it is not verbosity — it is that JSON has no way to represent text interleaved with structure.
- Attributes vs child elementsThe oldest argument in XML, and the only parts of it that are not taste: attributes cannot repeat, cannot nest, and cannot be extended later.
Get started
Bring order to the XML your team can't afford to ignore.
Create a free account and get a private workspace to search, validate, diff, and monitor your XML feeds, sitemaps, schemas, and vendor integrations.