Learn Programming, Tech & Coding · Free Online Tools

IT Question Answer
Back to XHTML
XHTML Syntax Rules Explained

XHTML Syntax Rules Explained

XHTML243 viewsBy Admin
xhtmlsyntaxrules

Advertisement

The Strict Rules of XHTML

Because XHTML is XML, it enforces rules that HTML treats as optional. Breaking any of them makes the document invalid.

1. All Tags Must Close

<p>Paragraph</p>
<br />  <!-- self-closing with space-slash -->
<img src="x.jpg" alt="x" />

2. Lowercase Everything

<DIV>  ❌
<div>  ✅

3. Quote All Attributes

<input type=text>     ❌
<input type="text" /> ✅

4. Properly Nest Tags

<b><i>text</b></i>   ❌ wrong order
<b><i>text</i></b>   ✅

5. Required Doctype & Root

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" ...>
<html xmlns="http://www.w3.org/1999/xhtml">

FAQs

What happens if I break a rule?

A strict XHTML parser shows an error and may refuse to render. More in our XHTML section.

Are these rules in HTML5?

Optional, but following them keeps your markup clean.

Advertisement