HTML vs XML vs XHTML: Differences Explained with Worked Examples

HTML is parsed forgivingly, XML stops at the first error, and XHTML is HTML written with XML's rules. Here is the difference rule by rule, five snippets run through a real XML parser and a real HTML parser, the current status of each spec as of November 2026, and where engineers still meet XML every day.

HTML vs XML vs XHTML: Differences Explained with Worked Examples

HTML is the language web pages are written in, and browsers parse it forgivingly: a missing end tag or a capitalised <P> is repaired by fixed rules. XML is a general format for data in which you invent your own tags, and a parser must stop at the first syntax error. XHTML is HTML written with XML's strict rules. As of November 2026, all three are defined by live specifications: the WHATWG HTML Living Standard (which now calls XHTML "the XML syntax" of HTML) and W3C's XML 1.0.

This guide compares them rule by rule, then runs five small worked examples through a real XML parser and a real HTML parser so you can see the difference instead of memorising it. The outputs shown are exactly what the parsers printed when Skill-Lync ran them on 22 November 2026.

Key takeaways

  • One HTML standard. Since the W3C-WHATWG agreement of 28 May 2019, HTML and the DOM are developed in the WHATWG Living Standard; the copy we read was last updated on 20 November 2026.
  • XHTML 1.0 and 1.1 are superseded. XHTML 1.0 (Recommendation 26 January 2000, revised 1 August 2002) and XHTML 1.1 were both marked "superseded" by W3C on 27 March 2018. Writing HTML in XML syntax is still allowed and still works.
  • XML 1.0 is in its Fifth Edition (26 November 2008). Its first edition became a W3C Recommendation on 10 February 1998.
  • The header decides the parser. A page sent as text/html is parsed as HTML; the same bytes sent as application/xhtml+xml are parsed as XML, and one stray & can stop the page from rendering fully.
  • XML is far from dead. Sitemaps, Atom feeds, SVG, Word's .docx files, EPUB e-books, AUTOSAR ARXML files and FMI model descriptions are all XML.

What is the difference between HTML, XML and XHTML?

HTML describes web pages with a fixed set of tags and is parsed leniently. XML describes any data with tags you define, and its parser rejects a document that is not well-formed. XHTML is HTML's vocabulary written in XML syntax: lowercase names, every element closed, every attribute quoted, served as application/xhtml+xml. Same page elements, stricter grammar.

The table puts the differences side by side. The rules come from the HTML Living Standard (syntax section), XML 1.0 Fifth Edition and the "Differences with HTML 4" section of XHTML 1.0.

PointHTMLXMLXHTML
PurposeWeb pagesAny dataWeb pages XML tools can read
SpecWHATWG Living StandardXML 1.0, 5th ed. (2008)XML syntax of HTML (XHTML 1.x retired 2018)
TagsFixed set + custom elementsYou define themHTML's, in XHTML's name­space
Case matters?NoYesYes, all lowercase
End tagsSome optionalRequiredRequired
Empty<br><x/><br/>
Quoting valuesOptionalRequired, with a valueRequired, with a value
ErrorsFixed up by spec rulesFatalFatal
Used forAlmost every web pageSitemaps, feeds, office files, configsEPUB 3 e-books

Media types: HTML is served as text/html, XML as application/xml (or text/xml, or any +xml type) and XHTML as application/xhtml+xml. In the table, "custom elements" means author-defined names that contain a hyphen; a trailing / on an HTML <br/> is allowed but does nothing; and in XHTML a bare HTML attribute such as checked must be written checked="checked".

What is XML?

XML (Extensible Markup Language) is a W3C format for storing and exchanging structured data as text. You choose the element names, nest them into one tree with a single root, and any XML parser can read the result. XML says nothing about display: the tags describe what the data is, and a program decides what to do with it.

XML 1.0 calls a document well-formed when it follows the grammar. The rules that trip people up most:

  • Exactly one root element contains everything else.
  • Every start tag has a matching end tag (or uses the empty-element form <area/>), and elements nest without overlapping.
  • Names are case-sensitive: <Load> and </load> do not match.
  • Attribute values are always in quotes.
  • A bare < or & in text must be written as &lt; or &amp;.

A document is additionally valid when it has a document type declaration (or, in practice, a schema) and obeys its constraints. Well-formed is the minimum any parser demands; valid is an extra contract between the producer and the consumer of the data.

Worked example 1: an engineering record in XML

Here is a tensile test reading stored as XML. The tag names are ours; nothing in XML defines tensileTest.

<?xml version="1.0" encoding="UTF-8"?>
<tensileTest specimen="T-07">
  <load unit="kN">12.5</load>
  <area unit="mm2">50</area>
</tensileTest>

Python's standard XML parser reads it into a tree of 3 elements and 3 attributes, and the script pulls the values out by name to compute the engineering stress:

specimen=T-07  F=12.5 kN  A=50.0 mm2
stress=250 MPa
Tree of the tensile test XML: root element tensileTest with attribute specimen T-07, child elements load (unit kN, text 12.5) and area (unit mm2, text 50); stress = 12.5 kN x 1000 / 50 mm2 = 250 MPa
The same document as the parser sees it: elements, attributes and text nodes in one tree. Drawn by Skill-Lync from the parsed example.

This is the job XML was built for: two programs that have never met can exchange this file, and the receiver knows that 12.5 is a load in kN because the markup says so.

What is HTML, and why does it forgive mistakes?

HTML (HyperText Markup Language) is the markup for web pages, maintained by the WHATWG as a Living Standard. Its parsing algorithm defines exactly how to handle every syntax error, so a conforming browser builds a page from broken markup instead of refusing it, and every conforming browser builds the same tree from the same broken markup. That is why sloppy HTML still renders.

The standard is explicit about it: certain points in the parsing algorithm are "parse errors", and "the error handling for parse errors is well-defined". Tag names in the HTML syntax are case-insensitive, and some end tags may be omitted because the parser can infer them.

Worked example 2: one sloppy snippet, two parsers

This fragment has an uppercase <P>, overlapping <b> and <i>, unclosed paragraphs, an unquoted attribute and a value-less checked:

<P>Stress: <b>210 <i>MPa</b></i>
<p>Load case 2<br>
<input type=checkbox checked>

The XML parser (expat, through Python's xml.etree) stops at the first problem:

ParseError: mismatched tag:
  line 1, column 26

Column 26 (expat counts from 0) is the b of </b>: the parser expected </i> first, because <i> was opened last. The HTML parser, which follows the WHATWG algorithm, builds a page and serialises this DOM:

<p>Stress: <b>210 <i>MPa</i></b>
</p><p>Load case 2<br>
<input type="checkbox" checked=""></p>

It lower-cased P, closed <i> before </b>, dropped the stray </i>, closed the first paragraph when the second began, and quoted the attribute. Nothing was refused.

Worked example 3: case sensitivity

<Load unit='kN'>12.5</load>
XML parser  -> mismatched tag:
               line 1, column 22

<DIV>ok</div>
HTML parser -> <div>ok</div>

In XML, Load and load are two different names. In HTML they are the same element.

What is XHTML, and is it still used?

XHTML is HTML written as XML. XHTML 1.0, a W3C Recommendation from 26 January 2000, reformulated HTML 4 in XML 1.0 without adding features. W3C marked XHTML 1.0 and 1.1 superseded on 27 March 2018; today the HTML Living Standard defines the same idea as "the XML syntax" of HTML, and EPUB 3 e-books still require it.

The history explains the confusion around the name. In 1998 W3C decided to stop evolving HTML and to build an XML-based equivalent instead, according to the HTML Standard's own history section. XHTML 1.0 followed in 2000 and XHTML 1.1 in 2001. Work also began on XHTML 2, which was not compatible with existing pages. Browser makers Apple, Mozilla and Opera, worried about that direction, founded the WHATWG in 2004 to keep evolving HTML itself. W3C let the XHTML 2 Working Group's charter expire at the end of 2009, published HTML5 as a Recommendation on 28 October 2014, and on 28 May 2019 agreed that HTML would be developed in one WHATWG Living Standard.

Timeline 1995-2026. HTML: 2.0 in 1995, 4.01 in 1999, WHATWG founded 2004, HTML5 Recommendation 28 Oct 2014, HTML 4.01 superseded and HTML5 retired 2018, W3C-WHATWG agreement 2019, Living Standard updated 20 Nov 2026. XML/XHTML: XML 1.0 in 1998, XHTML 1.0 in 2000, XHTML 1.1 in 2001, XML Fifth Edition 2008, XHTML 2 stopped 2009, XHTML 1.0 and 1.1 superseded 27 Mar 2018, EPUB 3.3 in 2023
Three decades of the two lines. Every date is from the W3C, WHATWG or IETF page listed under Sources.

So when an exam or an interviewer asks "what is XHTML", the complete 2026 answer has two parts: the XHTML 1.x family (historical, superseded) and the XML syntax of today's HTML (current, but rarely served on the open web because one error stops the page).

How does a browser decide whether a page is HTML or XHTML?

By the Content-Type header, not the doctype or the file's contents. A document sent as text/html is processed as HTML. A document sent with an XML media type such as application/xhtml+xml goes to the XML parser, where "even minor syntax errors will prevent a document labeled as XML from being rendered fully", in the HTML Standard's words.

Flowchart: bytes from the server, Content-Type read; text/html goes to the HTML parser which fixes errors by fixed rules and renders; application/xhtml+xml goes to the XML parser, which renders a well-formed document and stops on a well-formedness error
The media type, not the markup, picks the parser. XML 1.0 requires a conforming processor to report a fatal error and stop normal processing.

The application/xhtml+xml type was registered with IANA in January 2002 through RFC 3236; the registration notes that the extensions ".xhtml" and ".xht" are sometimes used. A file saved as page.html with perfect XHTML inside is still parsed as HTML when the server sends text/html.

Worked example 4: one unescaped ampersand

<p>Fe & C</p>
XML parser  -> not well-formed
   (invalid token): line 1, column 7
HTML parser -> <p>Fe &amp; C</p>

<p>Fe &amp; C</p>
XML parser  -> text = 'Fe & C'

A materials page that writes "Fe & C" with a bare ampersand renders fine as HTML. Served as XHTML, that one character is a fatal error. This is the practical reason most sites never switched to serving application/xhtml+xml.

How do you convert an HTML page to XHTML?

Apply XML's rules to the HTML: lowercase every element and attribute name, close every element, write empty elements as <br/>, quote every attribute value, give boolean attributes a value, escape bare & and <, add the XHTML namespace on <html>, and serve it as application/xhtml+xml. Then check it with an XML parser.

Worked example 5: a small page, before and after

The HTML version (any browser renders it):

<!DOCTYPE html>
<html lang=en>
<title>Beam check</title>
<P>Span: 4 m<br>
<input type=checkbox checked>
</html>

The XHTML version:

<!DOCTYPE html>
<html
  xmlns="http://www.w3.org/1999/xhtml"
  lang="en" xml:lang="en">
<head><title>Beam check</title></head>
<body>
<p>Span: 4 m<br/></p>
<input type="checkbox"
       checked="checked"/>
</body>
</html>

What the parsers said:

XML parser, HTML version:
  not well-formed (invalid token):
  line 2, column 11
XML parser, XHTML version:
  well-formed, root =
  {http://www.w3.org/1999/xhtml}html

Line 2, column 11 is the unquoted en. The XHTML version is well-formed, and its root element sits in the XHTML namespace.

One detail worth knowing for interviews: fed to the HTML parser, both versions give a page with head, title, body, p, br and input, but not the same tree. In the HTML version the unclosed paragraph swallows the checkbox, so input becomes a child of p; in the XHTML version the explicit </p> keeps it outside. Implied tags change structure, and structure changes what CSS selectors and scripts find.

Where are XML and XHTML used today?

XML lost the web-page battle but won as a file and exchange format. Search engines read XML sitemaps, feed readers read Atom, browsers draw SVG, Word saves .docx as zipped XML, e-readers open XHTML inside EPUB, and automotive and simulation tools exchange AUTOSAR ARXML and FMI model descriptions. Engineers meet XML long before they meet XHTML.

Where (spec)What the XML does
XML sitemaps
sitemaps.org protocol
Lists a site's URLs for search engines; at most 50,000 URLs and 50 MB (52,428,800 bytes) uncompressed per file
Atom feeds
RFC 4287, December 2005
Blog and news feeds
SVG graphics
SVG 2, W3C Candidate Recommendation Snapshot, 6 October 2026
Vector images, including every figure on this page
Word, Excel, PowerPoint
ECMA-376 / ISO/IEC 29500, Part 2, 5th edition, December 2021
A .docx is a ZIP package of XML parts (Open Packaging Conventions)
EPUB e-books
EPUB 3.3, W3C Recommendation, 2023
Each chapter is an XHTML content document that "MUST be an HTML document that conforms to the XML syntax"
AUTOSAR (automotive software)
ARXML Serialization Rules, R22-11
Model descriptions exchanged between AUTOSAR tools as ARXML files, which must validate against the AUTOSAR XML Schema
FMI co-simulation
FMI 3.0
Each Functional Mock-up Unit carries a modelDescription.xml listing its variables and capabilities
Ansys ACT extensions
see our Ansys ACT XML syntax post
Buttons and wizards are defined in an XML file, with Python for the logic

If you are heading into automotive embedded work, ARXML is where you will read and diff XML every week; in simulation, an FMU's modelDescription.xml is the first file to open when a co-simulation refuses to connect.

HTML, XML and XHTML interview questions (with worked answers)

Is <br/> valid in HTML?

Yes. On void elements such as br, img and input, the HTML syntax allows a trailing slash and gives it no meaning. It does not make other elements self-closing: <div/> in HTML is just an opening div tag, which is why copying XHTML habits into HTML can nest content by accident. Our parser run confirms it: <br/>after becomes <br>after, while <div/>inside? becomes <div>inside?</div>.

What is the difference between well-formed and valid XML?

Well-formed means the document obeys XML's grammar: one root, matched and properly nested tags, quoted attributes, escaped special characters. Valid means it is well-formed and also follows a declared document type or schema. Every valid document is well-formed; a well-formed document can still be invalid for a given schema.

Can an XML document have two root elements?

No. XML 1.0 says there is exactly one element, called the root or document element, that contains all others. Two top-level elements make the document not well-formed. HTML has a single root too, but the HTML parser creates the html element itself when the markup leaves it out.

Why does a page work as .html but break as .xhtml?

Because the media type switches the parser, and servers usually pick it from the file extension. Served as application/xhtml+xml, the page goes through an XML parser, and any well-formedness error (a bare &, an unclosed <p>, <P> closed by </p>) is fatal. Served as text/html, the same errors are repaired silently by the HTML parsing rules.

Where to learn this hands-on

Reading the specs helps, but the differences stick once you have broken a page yourself. Skill-Lync's Complete Front-End Development course (12 weeks, online) covers HTML5, CSS, Bootstrap, JavaScript, AJAX and JSON with two projects. For the full path from markup to servers and databases, see the Pre-Graduate Program in Full Stack Web Development (16 weeks) or the Post Graduate Program in Full Stack Web Development (24 weeks). If you are unsure which fits, talk to a Skill-Lync counsellor. For the bigger picture, read front-end, back-end and full-stack development explained.

Frequently asked questions

Is XHTML dead in 2026?

The XHTML 1.0 and 1.1 specifications are: W3C marked both superseded on 27 March 2018. The idea is not. The HTML Living Standard still defines an XML syntax for HTML, browsers still parse application/xhtml+xml, and EPUB 3.3 requires every e-book chapter to be HTML in XML syntax. New websites almost always use plain HTML.

Is HTML a subset of XML?

No. HTML has its own syntax and parser, with optional end tags, unquoted attributes and case-insensitive names that XML forbids. XML grew out of SGML, and HTML 4 was formally an SGML application, but today's HTML is defined by its own WHATWG parsing rules. XHTML is the variant that is written as XML.

Should a beginner learn HTML, XML or XHTML first?

Learn HTML first: it is what every web page uses and what front-end jobs test. Learn XML's well-formedness rules next, because they take an hour and appear everywhere from sitemaps to automotive ARXML. XHTML then needs no separate study: it is simply HTML written with those XML rules.

Has JSON replaced XML?

For web API payloads, JSON (RFC 8259) is the usual choice because it maps directly to objects in code. XML remains the format where documents mix text and markup, need namespaces or schema validation, or must follow an industry standard such as Office Open XML, EPUB, AUTOSAR or FMI. Most engineers end up reading both.

What does "extensible" mean in XML and XHTML?

In XML it means you can define new element names for your data instead of using a fixed list. In XHTML it meant HTML could be mixed with other XML vocabularies through namespaces, for example SVG or MathML inside a page. HTML now embeds SVG and MathML directly, and offers custom elements with hyphenated names.

Sources and further reading

Want this on your résumé?

Talk to a counsellor.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.