freecoding.school100% FREE · NO SIGNUP
The Old NetISSUE #24 of 60

converting html to xhtml

Pixel PeteVSQuirks Mode
Pixel Pete saysConverting HTML to XHTML is mechanical: lowercase, close, quote, nest, escape, add namespace.

The migration recipe: lowercase all tags/attributes, close every element (self-close voids), quote all values, fix nesting, escape stray &/<, expand boolean attributes, and add the doctype + xmlns. Tools like HTML Tidy automate most of it. Then serve as application/xhtml+xml to actually get XML parsing.

Power-ups you unlock

Quirks Mode attacks — common mistakes

Boss battleList the conversion steps in order for one messy HTML snippet.

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre>HTML:  &lt;DIV class=x&gt;a &amp; b&lt;BR&gt;&lt;/DIV&gt;
XHTML: &lt;div class="x"&gt;a &amp;amp; b&lt;br /&gt;&lt;/div&gt;</pre></body></html>
▶ Open the interactive comic issue
‹ When Xhtml Still Matters · E-Readers · EpubReferences · Spec Links · Validators ›