HTML and CSS Reference
In-Depth Information
16.3.2. End Tags
As we've documented throughout this topic, any HTML tag that contains
other tags or content has a corresponding end tag. However, one of the
hallmarks of HTML (codified in the 4.01 standard) is that you may leave
out the end tags if the processing agent can infer their presence. This
is why most of us HTML authors commonly leave out the </p> end tag
between adjacent paragraphs. Also, lists and tables can be complicated
to wade through, and not having to visually stumble over all the </li> ,
</td> , </th> , and </tr> end tags certainly makes HTML easier to read,
albeit a bit more ambiguous.
This is not so for XHTML. Every tag that contains other tags or content
must have a corresponding end tag present, correctly nested within the
XHTML document. A missing end tag is an error and renders the docu-
ment noncompliant. Although seemingly draconian, this and the nesting
rules nonetheless remove any and all ambiguities as to where one tag
starts and another tag ends.
16.3.3. Handling Empty Elements
In XML, and thus XHTML, every tag must have a corresponding end
tageven those that aren't allowed to contain other tags or content. Ac-
cordingly, XHTML expects the line break to appear as <br></br> in your
document. Ugh.
Fortunately, there is an acceptable alternative: include a slash before
the closing bracket of the tag to indicate its ending (e.g., <br /> ). If the
tag has attributes, the slash comes after all the attributes so that an im-
age could be defined as:
<img src="kumquat.gif" />
While this notation may seem foreign and annoying to an HTML author,
it actually serves a useful purpose. Any XHTML element that has no con-
Search WWH ::

Custom Search