HTML vs. XHTML
I like to imagine HTML as a laid-back don't-sweat-the-details kind of person. Perhaps not quite as hard-working as XHTML, but much
and at ease with herself. XHTML, on the other hand is downright uptight. Always vigilant, never taking a rest. Sure, she gets more done, but what a price!
Before I go off the deep end with my personification of Web page code types, let me tell you the specifics. For starters, know that HTML 4 and XHTML 1.0 use
precisely the same
elements, attributes, and values. The difference is in the syntax.
Where HTML doesn't care if you use the
, XHTML requires them.
Where HTML lets you omit some closing tags, XHTML insists on them for every element, even empty ones. For the best compatibility with browsers, add a space and / to empty elements and include an independent closing tag for non-empty elements
. Note that the slash is not
valid in empty elements in HTML, though all browsers I've seen simply ignore it.
Figure 1.25. In HTML, some elements, like
, do not require a closing tag. Subsequent
tags implicitly close earlier ones.
Figure 1.26. In XHTML, all elements must have closing tags.
Figure 1.27. In HTML, empty elements do not have a final slash, though browsers won't complain if they do.
Figure 1.28. In XHTML, even empty elements must have a closing tag. While an independent closing tag for an empty element, like
, would be technically correct, adding a space and / to the single
tag ensures compatibility with non-XHTML-savvy browsers.
Where HTML lets you omit quotes around attribute values that contain just
and four simple symbols (-, ., _, and :), XHTML gets nightmares (and generates errors) if you leave quotes out
Figure 1.29. In HTML, attribute values only need to be quoted when they contain spaces or other special
(anything besides letters, numbers, hyphens, periods, underscores, or colons). So, in this example, only the
attribute's value must be quoted (though it wouldn't hurt to quote all of them).
Figure 1.30. In XHTML, all attribute values must always be
Where HTML is flexible about case, XHTML is not, demanding that all elements, attributes, and predefined values be in lowercase
Figure 1.31. In HTML, it doesn't matter if you write element names, attribute
, or predefined values in upper- or lowercase.
Figure 1.32. In XHTML, all element names, attribute names, and predefined values must be written in lowercase.
Where HTML allows you to omit values that have the same
as the attribute, XHTML insists that all values be stated explicitly
Figure 1.33. In HTML, some attributes, like
shown here, don't require any value.
Figure 1.34. In XHTML, attribute values must be stated explicitly. For those attributes that in HTML have no value, simply repeat the attribute's name as its value.
What do you get for your troubles?
You might be wondering if it's worth it to worry about every last quotation mark. The answer is, it depends.
XHTML's rigidity affords a lot of advantages. Think of a clean workshop, with hammers and screwdrivers hanging in their places on the wall and all the nuts and bolts in labeled containers. It's so easy to find what you need that it makes projects a hundred times easier. Similarly, XHTML helps you keep your code consistent, well structured, and free of nonstandard tags, which in
makes it easier to update and edit, to format with CSS, to generate from or convert into a database, and to adapt for other systems, like handhelds.
In addition, XHTML is a logical step in the transition from HTML to XML, since it uses familiar HTML elements and attributes together with modern XML syntax. And since XHTML is the new standard, you can be sure that it will be used with other new and future technologies.
Perhaps one of XHTML's most important gifts is that its insistence on standards makes it more likely to be properly and consistently supported by current browsers, on all platformswhich makes good business sense. And since Web page accessibility is now required by U.S. law, and the laws of many other nations, it is something that should not be ignored. For more information on accessibility laws, visit the W3C Web Accessibility Initiative at
For more details about why standards matter, I recommend a trip to The Web Standards Project
, a consortium of designers turned diplomats determined to end the browser wars, and Jeffrey Zeldman's
A List Apart
online magazine for Web designers