HTML: The Definitive Guide

Previous Chapter 4 Next
 

4.2 Headings

Users have a hard enough time reading what's displayed on a screen. A long flow of text, unbroken by title, subtitles, and other headers, crosses eyes and numbs the mind, not to mention the fact that it makes it nearly impossible to scan the text for a specific topic.

You should always break a flow of text into several smaller sections within one or more headings (like this book!). HTML defines six levels of headings that can be used to structure a text flow into a more readable, more manageable document. And, as we discuss in Chapter 5, Rules, Images, and Multimedia, there are a variety of graphical tricks that help divide your HTML document and make its contents more accessible as well as more readable to users.

Heading Tags

The six heading tags, written as <h1>, <h2>, <h3>, <h4>, <h5>, and <h6>, indicate the highest (<h1>) to the lowest (<h6>) precedence a heading may have in the document.

The enclosed text within a heading typically is uniquely rendered by the browser, depending upon the display technology available to it. The browser may choose to center, embolden, enlarge, italicize, underline, or change the color of headings to make each stand out within the document. And to thwart the most tedious HTML writers, users, too, often can alter how a browser will render the different headings. Ah, well.

Fortunately, in practice most browsers use a diminishing character point size for the sequence of headers, so that <h1> text is quite large and <h6> text is quite minuscule (see Figure 4-3, for example).

By tradition, HTML authors have come to use <h1> headers for document titles, <h2> headers for section titles, and so on, often matching the way many of us were taught to outline our work with heads, subheads, and sub-sub-a-dub-heads.

Finally, don't forget to include the appropriate heading end tags in your document. The browser won't insert one automatically for you, and omitting the ending tag for a heading can have disastrous consequences for your document.

The align attribute

It has become de rigueur for browsers to let HTML authors align text inside structural tags like <p> and <div>. The headings tags are no different: The latest versions of the popular browsers, for instance, support an align attribute for headings.

The default alignment for most browsers is left. Internet Explorer lets you specially center a particular heading, whereas Netscape and Mosaic support all three of the common alignment attribute values: left, center, and right. Figure 4-4 shows these alternative alignments as rendered from the following source:

<h1 align=right>Right over here!</h1>
<h2 align=left>Slide back left.</h2>
<h3 align=center>Smack in the middle.</h3>

Appropriate Use of Headings

It's good form to repeat that title in the first heading tag, since the title you specify at the beginning of your HTML document doesn't appear in the user's main display window. It should match the title in the document header. The HTML segment:

<html>
<head>
<title>Kumquat Farming in North America</title>
</head>
<body>
<h3>Kumquat Farming in North America</h3>
<p>
Perhaps one of the most enticing of all fruits is the...

is a good example of repeating the document's title in the header and in the body of document. While the browser may place the title somewhere in the document window and may also use it to create bookmarks or hotlist entries, all of which vaguely are somewhere on the user's desktop, the level-3 title heading in the example will always appear at the very beginning of the document. It serves as a visible title to the document regardless of how the browser handles the <title> tag contents. And, unlike the <title> text, the heading title will appear at the beginning of the first page should the user elect to print the document. [<title>, 3.6.2]

In the example, we chose to use a level-3 header (<h3>) whose rendered font typically is just a bit larger than the regular document text. Levels one and two are larger still and often a bit overbearing. You should choose a level of heading that you find useful and attractive and use that level consistently throughout your documents.

Once you have established the top-level heading for your document, use additional headings at the same or lower level throughout to add structure and ``scanability'' to the document. If you use a level-3 heading for the document title, break your document into several sections using level-4 headings. If you have the urge to subdivide your text further, consider using a level-2 heading for the title, level-3 for the section dividers, and level-4 for the subsections.

Using Headings for Smaller Text

For most graphical browsers, the fonts used to display <h1>, <h2>, and <h3> headers are larger, <h4> is the same, and <h5> and <h6> are smaller than the regular text size. HTML writers typically use the latter two sizes for boilerplate text, like a disclaimer or a copyright notice. Experiment with <h5> and <h6> to get the effect you want. See how a typical browser renders the copyright reference in the following sample HTML segment (Figure 4-5):

resulting in years of successful kumquat production 
throughout North America.
</p>
<h6>This document copyright 1995 by the Kumquat Growers of 
America. 
<br>
All rights reserved. </h6>
</body>
</html>

Allowed Heading Content

A heading may contain any element allowed in text, including conventional text, link anchors (<a>), images (<img>), line breaks (<br>), font embellishments (<b>, <i>, <tt>, <u>, <strike>, and <font>), and content-based style changes (<cite>, <code>, <em>, <kbd>, <samp>, <strong>, and <var>).

In practice, however, font or style changes may not take effect within a heading, since the heading itself prescribes a font change within the browser.

There is widespread abuse of the heading tags as a mechanism for changing the font of an entire document. Technically, paragraphs, lists, and other block elements are not allowed within a heading and may be mistaken by the browser to indicate the implied end of the heading. In practice, most browsers apply the style of the heading to all contained paragraphs. We discourage this practice since it is not only a violation of the HTML standard, but usually ugly to look at. Imagine if your local paper printed all the copy in headline type!

Allowed Heading Usage

Formally, the HTML standard allows headings only within body_content. In practice, most browsers recognize headings almost anywhere, formatting the rendered text to fit within the current element. In all cases, the occurrence of a heading signifies the end of any preceding paragraph or other text element. So you can't use the headings tags to change font sizes in the same line. Netscape and Internet Explorer, however, have special extensions for inline font size adjustments within a heading; see 4.6 for details.

Adding Images to Headings

It is possible to insert one or more images within your headings, from small bullets or icons to full-sized logos. Combining a consistent set of headings with corresponding icons across a family of documents is not only visually attractive, but an effective way of aiding users' perusal of your document collection. [<img>, 5.2.6]

Adding an image to a heading is easy. For example,

<h2>
<img src="info.gif">
For More Information</h2>

puts an ``information'' icon inside the ``For More Information'' heading as you can see in Figure 4-6.

In general, images within headings look best at the beginning of the heading, aligned with the bottom or middle of the heading text.


Previous Home Next
Divisions and Paragraphs Book Index Changing Text Appearance