DOs and DONTs

Sr.No.
Topics
1

Avoid Overlapping Tags

2
Embed Only Anchors and Character Tags
3
Finishing Touches
4
Commenting Your Files

Embed Only Anchors and Character Tags

HTML protocol allows you to embed links within other HTML tags:

    <H1><A HREF="Destination.html">My heading</A></H1>

Do not embed HTML tags within an anchor:

    <A HREF="Destination.html">
    <H1>My heading</H1>
    </A>

Although most browsers currently handle this second example, the official HTML specifications do not support this construct and your file will probably not work with future browsers. Remember that browsers can be forgiving when displaying improperly coded files. But that forgiveness may not last to the next version of the software! When in doubt, code your files according to the HTML specifications.

Character tags modify the appearance of the text within other elements:

    <UL>
    <LI><B>A bold list item</B>
    <LI><I>An italic list item</I>
    </UL>

Avoid embedding other types of HTML element tags. For example, you might be tempted to embed a heading within a list in order to make the font size larger:

    <UL>
    <LI><H1>A large heading</H1>
    <LI><H2>Something slightly smaller</H2>
    </UL>

Although some browsers handle this quite nicely, formatting of such coding is unpredictable (because it is undefined). For compatibility with all browsers, avoid these kinds of constructs. (The Netscape <FONT> tag, which lets you specify how large individual characters will be displayed in your window, is not currently part of the official HTML specifications.)

What's the difference between embedding a <B> within a <LI> tag as opposed to embedding a <H1> within a <LI>? Within HTML the semantic meaning of <H1> is that it's the main heading of a document and that it should be followed by the content of the document. Therefore it doesn't make sense to find a <H1> within a list.

Character formatting tags also are generally not additive. For example, you might expect that:

    <B><I>some text</I></B>

would produce bold-italic text. On some browsers it does; other browsers interpret only the innermost tag.