XHTML is HTML written as XML. XHTML 1.0 (2000) is now a Superseded Recommendation; the HTML Living Standard defines both syntaxes, and a browser picks one by media type: text/html gets the forgiving HTML parser, application/xhtml+xml (or a .xhtml file) the XML parser, which stops at the first error. This page forgets to close a <br>:
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head><title>Salt and Saffron</title></head>
<body>
<h1>Salt and Saffron</h1>
<p>Coastal recipes from Kerala to Zanzibar.<br>
Price: $24.00</p>
</body>
</html>
Served as text/html, the same bytes render without complaint. XHTML matters where pages are data: EPUB content documents are XHTML, and XHTML exports go straight into XSLT or lxml 3,063 .
XHTML
Extensible HyperText Markup Language (XHTML) is a stricter version of HTML, in the sense that a document must be well-formed in the XML sense. Its development was motivated by interoperability with other formats, since an XHTML document can be processed by an XML processor. XML namespaces also let an XHTML document be extended by other XML-based languages, such as SVG and MathML.Two stable versions of XHTML exist: 1.0 and 1.1. XHTML 1.1 adds modularization, along with ruby annotation elements (ruby, rbc, rtc, rb, rt, and rp). XHTML is supported by all major browsers.
Besides the requirement to be well-formed in the XML sense, an XHTML document differs from an HTML document in several other important respects:
- An XHTML document begins with an XML declaration.
- The DOCTYPE declares the document to be XHTML-compliant.
- The root element, <html>, carries an xmlns attribute relating it to the XHTML namespace.
- All tag names and attribute names must be lowercase in XHTML.
- Attribute minimization is not allowed in XHTML. For instance, <textarea readonly> is incorrect; use <textarea readonly="readonly"> instead.
<?xml version="1.0" encoding="UTF-8"?>
<!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>
<title>XHTML 1.0 Strict Example</title>
<script type="application/javascript">
<![CDATA[
function start() {
alert("Hello World");
}
]]>
</script>
</head>
<body onload="start()">
<p>The name of an XHTML file ends with .xhtml.</p>
</body>
</html>