XHTML vs. HTML

The question of whether to use XHTML or HTML will often not even come up in an average
web project; most web designers these days will naturally gravitate toward XHTML, as
it is perceived as being new, advanced, and the “X” makes it sound cool. The truth is,
XHTML isn’t as different from HTML as people think, and the purpose of this section of the
chapter is to discuss exactly how XHTML differs from earlier versions of HTML, debunk
some myths and misconceptions about XHTML and HTML, examine the issues behind
MIME types, and cover when it is (and isn’t) appropriate to use XHTML over HTML.

Differences between XHTML and HTML

There are several rules that apply to XHTML that do not apply to HTML. These are fairly
straightforward and you may know some (or all) of them already, but to reiterate:

The <html>, <head>, and <body> tags are all required in XHTML.

The <html> tag must have an xmlns attribute with a value of http://www.w3.org/
1999/xhtml.

All elements must be closed. I touched upon this earlier, but just remember that an
opening tag must have either an equal closing tag (if it’s a container tag) or a selfclosing
space-plus-slash.

All tags must be written in lowercase.

All attribute values must be quoted with either single quotes or double quotes.
Thus, class=page is invalid but class="page" and class='page' are both fine.

All attributes must have values. Some attributes, such as the selected attribute
used with the <option> tag, could be written in a shortened form in HTML—that is,
<option selected>data</option> would be valid. In XHTML, however, you must
write <option selected="selected">data</option>.

Ampersands should be encoded. That is, you should write &amp; instead of just &.
This is true wherever the ampersand is: in your content or in a URL.