Datasheet
<tr>
<td>Cell 3</td>
<td>Cell 4</td>
</tr>
</table>
Notice how the tags are closed in the opposite order they were opened. Although intuitive for structures
like tables, it isn’t always as intuitive. For example, consider the following fragment where the phrase
“italic and bold” is formatted with italic and bold tags:
This sentence uses
<b><i>italic and bold</b></i> tags for emphasis.
Although this example would generally not cause a problem when rendered via a user agent, there are
many instances where overlapping tags can cause problems. Well-formed HTML always uses nested
tags — tags are closed in the exact opposite order that they were opened.
Simple Rules for Formatting HTML Documents
As with most programming languages, formatting plays a big role in writing Web documents that not
only display as intended but also are easily understood and maintained. These simple rules should
always be followed when creating Web documents:
❑ Use liberal white space. Browsers ignore superfluous white space, so you can make use of it to
create documents that are more easily read and maintained. Insert blank lines and follow stan-
dard coding rules for indentation whenever possible.
❑ Use well-formed code. This means following the XHTML standard to the letter — not taking
shortcuts that some browsers allow. In particular, you should pay attention to the following:
❑
Always include a <doctype> tag (<doctype> and other document-level tags are dis-
cussed in Chapter 2.
❑ Elements (tags) must be nested, not overlapping.
❑ All nonempty elements need to be terminated. Most browsers allow for nonclosed
elements, but to meet the XHTML standard you need to supply closing tags for each
open one (for example, supply a closing paragraph tag [
</p>] for every open one
[
<p>]).
❑ All tags need to be closed. Although the HTML standard allows tags such as <hr>
without a closing tag —in fact, the <hr> tag has no closing mate — in XML all tags
must be closed. In the case of tags like
<hr>, you close the tag by putting a slash at the
end of the tag:
<hr />.
❑ All attribute values must be quoted. Again, most browsers allow nonquoted
attributes, but the XHTML standard does not.
❑ All attributes must have values. Older HTML standards allowed for tags similar to
the following:
<input type=”checkbox” checked>
10
Chapter 1
04_588206 ch01.qxd 6/30/05 12:36 AM Page 10