Tuesday, September 14, 2010

The importance of end tags

While we’re on the subject of well-formed markup, we’ll revisit the importance of end
tags. As mentioned earlier, XHTML demands that all tags be closed. Most browsers let you
get away with ignoring some end tags, though, such as on paragraphs. Some designers may
still have bad habits from working with HTML, for which many end tags are optional. Omit
many others at your peril. For instance, overlook a heading element end tag and a browser
considers subsequent content to be part of the heading and displays it accordingly. As
shown in the following image, two paragraphs are displayed as a heading because the earlier
heading element lacks an end tag.

 

A similar problem occurs when you accidentally omit end tags when using logical and
physical elements. For instance, forget to close an emphasis element and the remainder of
the web page may be displayed in italics.

Some designers when hand-coding create both start and end tags at the same time,
and then populate the element with content, ensuring end tags are not forgotten.

No comments:

Post a Comment