HTML vs XHTML
In this page:
What is XHTML?
XHTML (Extensible HyperText Markup Language) is a strict, XML-based markup language that was designed to replace HTML. It enforces strict formatting rules to ensure web pages can be parsed cleanly by any system.
Example: What is XHTML?
<html xmlns="http://www.w3.org/1999/xhtml">
</html>
Strict Tag Closing Rules
In standard HTML, closing tags on some elements (like paragraphs) is optional, and self-closing tags (like images) do not require a closing slash.
In XHTML, every single element must have a corresponding closing tag, and self-closing tags must end with a trailing slash.
Example: Strict Tag Closing Rules
<p>HTML allows this</p>
<img src="photo.jpg" alt="Photo" />
Case Sensitivity and Lowercase Tags
Standard HTML is case-insensitive, meaning you can write your tags in uppercase or lowercase. XHTML is strictly case-sensitive and requires all tag and attribute names to be written in lowercase.
Example: Case Sensitivity and Lowercase Tags
<p>Correct XHTML: lowercase tags</p>
Strict Attribute Value Rules
In standard HTML, you can write shorthand attributes like disabled or readonly without values, and omit quotes around single-word attribute values.
XHTML prohibits attribute shorthand and requires all attribute values to be written in lowercase and wrapped in double quotes.
Example: Strict Attribute Value Rules
<input type="checkbox" disabled="disabled">
Nesting Constraints and Overlapping
HTML is forgiving with nesting errors and will try to fix overlapping tags automatically. XHTML is strictly structured and requires all elements to be closed in the exact reverse order that they were opened.
Example: Nesting Constraints and Overlapping
<div>
<p>Correctly nested and closed in reverse order</p>
</div>
- Forgetting to include trailing slashes on self-closing tags in XHTML documents.
- Using shorthand attributes (like disabled instead of disabled="disabled") inside XHTML code.
- Nesting tags in the wrong order, causing XML validation to fail.
- HTML is a flexible, relaxed markup standard, while XHTML is a strict, XML-based markup standard.
- XHTML requires all tags to be written in lowercase, closed cleanly, and nested in the correct sequential order.
- Shorthand attributes are prohibited in XHTML; all attributes must write out complete values wrapped in double quotes.
Standard web browsers support both flexible HTML5 and strict XHTML formats natively.
Chapter Quiz — Complete all 10 topics to unlock
0/10 topics done
Complete these topics first: