- Asked 2/4
- 2076 Chaitra · 3 marks
- 2068 Chaitra (old course) · 5 marks
XHTML versus HTML
Short answer
XHTML is a stricter, XML-based reformulation of HTML. It requires lowercase tags, closed elements, quoted attributes, proper nesting, and a mandatory DOCTYPE, whereas HTML is more forgiving, allowing optional tags and case-insensitivity.
How is XHTML different from HTML?
HTML (HyperText Markup Language) is the standard language for web pages and has loose syntax rules. XHTML (Extensible HTML) is HTML reformulated as an XML application, so it must follow XML's strict rules.
| Basis | HTML | XHTML |
|---|---|---|
| Based on | SGML | XML |
| Tag case | Case-insensitive (<P> = <p>) | Tags and attributes must be lowercase |
| Closing tags | Some may be omitted (<p>, <li>) | Every element must be closed |
| Empty elements | <br>, <img ...> | <br />, <img ... /> |
| Nesting | Wrong nesting often tolerated | Must be properly nested |
| Attribute values | Quotes optional | Must be quoted: width="100" |
| Attribute minimisation | <input checked> allowed | checked="checked" required |
| Root element | <html> optional in practice | <html xmlns="http://www.w3.org/1999/xhtml"> required |
| DOCTYPE | Optional/relaxed | Mandatory |
| Error handling | Browser forgives errors | Parser stops on a well-formedness error |
| MIME type | text/html | application/xhtml+xml (or text/html) |
| Parsing | Not XML-parsable | Can be processed by XML tools |
Example:
<!-- HTML -->
<p>First<br>
<input type=text name=a>
<!-- XHTML -->
<p>First<br />
<input type="text" name="a" /></p>
XHTML therefore gives cleaner, well-formed, more portable code, but HTML5 later became the main standard because it is more forgiving.
✓ Answer checked by Claude Opus 5.5 (high effort)