Introduction to XHTML
What is XHTML?
XHTML stands for Extensible Hypertext Markup Language.
Developed by the W3C (World Wide Web Consortium), XHTML is more strict and
cleaner than HTML.
XHTML documents must be well-formed and follow strict syntax rules.
What is XML?
XML stands for Extensible Markup
Language.
It is a markup language designed to
store and transport data.
Unlike HTML, XML is not concerned
with how data looks, but rather what the
data "is".
It allows users to create their own tags
and define document structures.
Difference Between XHTML and HTML
Features HTML XHTML
Syntax Flexible Strict
Tag closing Optional for some tags Mandatory
Case sensitivity Not case sensitive Tags must be lowercase
Compatibility Browser specific XML-compliant parsers
Structure Can be loose Must be well-formed
Proper Nesting
Tags in XHTML must be properly nested.
Incorrect: <b><i>Text</b></i>
Correct: <b><i>Text</i></b>
Improper nesting can cause display or validation errors in XHTML documents.
Proper Tag Closing
All XHTML elements must be closed.
Examples:
- Self-closing tags must end with '/': <br />
- Paired tags must close: <p>Paragraph</p>
Elements in Lowercase
All tags and element names in XHTML must be written in lowercase.
Example:
- Correct: <html>, <body>
- Incorrect: <HTML>, <Body>
This rule ensures XML compatibility.
One Root Element
Every XHTML document must have exactly one root element.
Typically, this is the <html> element which wraps all other content.
Structure:
<html>
<head></head>
<body></body>
</html>
Attributes in Lowercase
Attribute names must also be in lowercase and properly quoted.
Correct: <input type='text' value='Hello' />
Incorrect: <input TYPE=TEXT VALUE=Hello>
Basic XML Rules
- Must have one root element.
- Tags must be properly nested.
- Tags must be closed.
- Attribute values must be in quotes.
- Case-sensitive: <Title> is different from <title>.
Create xhtml file
File extension is .xhtml
XHTML example
Result
Comparison
HTML XHTML
Result
HTML XHTML
Result after
removing / in
<br>.