This XHTML tutorial demonstrates how to code web pages using XHTML. It assumes that you're already comfortable with HTML. XHTML is almost identical to HTML with only a handful of differences. XHTML is slightly more strict than HTML and requires a little more attention when coding.
XHTML was developed by the W3C to help web developers make the transition from HTML to XML. So if you want to learn XML, XHTML is a good place to start.
Here are the main things to remember when writing XHTML:
- The root element of the document must be
- The root element must contain a
xmlnsdeclaration for the XHTML namespace
- Must have a DOCTYPE declaration, and it must come before the
- All XHTML tags are lower case
- Close all tags (even empty elements)
- Attribute values must be quoted
- Minimization is forbidden
idattribute replaces the
languageattribute of the
scripttag is deprecated
- Proper nesting of tags
Here's a more detailed explanation of the above XHTML rules.
The Root Element
The root element of the document must be
html. Read more about the
All XHTML documents must have an
xmlns declaration for the XHTML namespace (i.e.
http://www.w3.org/1999/xhtml). Read more about the HTML
All XHTML documents must have a DOCTYPE declaration. The document must include the usual html, head, title, and body elements.
All XHTML tags should be lower case. (HTML tags on the other hand, can be upper or lower case).
All tags should have an opening tag and a closing tag. If it's a tag that doesn't have a closing tag (for example, the
img tag, or the
hr tag, use a space and forward slash (/) before the > sign. (Note that the XHTML specification does not require a space before the "/" but this is required to conform with some browsers).
In XHTML, all attribute values must be quoted. (In HTML on the other hand, you could get away without quoting attribute values).
Minimization is forbidden. You should explicitly state the attribute and the value.
The id attribute
The id attribute replaces the name attribute. Instead of using
language attribute of the
script tag is deprecated.
All tags must be nested properly.
Apart from these strict rules, you can code your XHTML pages just like you've been coding HTML pages. To learn more about coding HTML, check out the HTML tutorial.