Even though XHTML supports the same elements and attributes as HTML 4.0, there are some significant differences that are due to the fact that XHTML is an XML-based language. Given your knowledge of XML, you may already have a pretty good idea regarding some of these differences, but the following list will help you to understand exactly how XHTML documents differ from HTML documents:
-
XHTML documents must be well formed.
-
Element and attribute names in XHTML must be in lowercase.
-
End tags in XHTML are required for nonempty elements.
-
Empty elements in XHTML must consist of a start-tag/end-tag pair or an empty element.
-
Attributes in XHTML cannot be used without a value.
-
Attribute values in XHTML must always be quoted.
-
An XHTML namespace must be declared in the root
html
element. -
The
head
andbody
elements cannot be omitted in XHTML. -
The
title
element in XHTML must be the first element in thehead
element. -
In XHTML, all script and style elements must be enclosed within
CDATA
sections.
These differences between XHTML and HTML 4.0 shouldn't come as too much of a surprise. Fortunately, none of them are too difficult to find and fix in HTML documents, which makes the move from HTML 4.0 to XHTML relatively straightforward. However, web pages developed with versions of HTML prior to 4.0 typically require more dramatic changes. This primarily has to do with the fact that HTML 4.0 does away with some previously popular formatting attributes such as background and instead promotes the usage of style sheets. Because XHTML doesn't support these formatting attributes, it is necessary first to convert legacy HTML (prior to 4.0) documents to HTML 4.0, which quite often involves replacing formatting attributes with CSS equivalents. Once you get a web page up to par with HTML 4.0, the move to XHTML is pretty straightforward.