HTML: The Definitive Guide

Previous Chapter 4 Next
 

4.4 Content-based Style Tags

It takes discipline to use the content-based styles, since it is easier to simply think of how your text should look, not necessarily what it may also mean. Once you get started using content-based styles, your documents will be more consistent and better lend themselves to automated searching and content compilation.

The <cite> Tag

The <cite> tag usually indicates that the enclosed text is a bibliographic citation like a book or magazine title. By convention, the citation text is rendered in italic. For example, NCSA's Mosaic renders the source:

While kumquats are not mentioned in Melville's
<cite>Moby Dick</cite>, it is nonetheless apparent
that the mighty cetacean represents the bitter 
"kumquat-ness" within every man. Indeed, when Ahab
spears the beast, its flesh is tough, much like the noble fruit.

as shown in Figure 4-7.

Use the <cite> tag to set apart any reference to another document, especially those in the traditional media, such as books, magazines, journal articles, and the like. If an online version of the referenced work exists, you also should enclose the citation within the <a> tag and make it a hyperlink to that online version.

The <cite> tag also has a hidden feature: it enables you or someone else to automatically extract a bibliography from your documents. It is easy to envision a browser that compiles tables of citations automatically, displaying them as footnotes or as a separate document entirely. The semantics of the <cite> tag go far beyond changing the appearance of the enclosed text; they enable the browser to present the content to the user in a variety of useful ways.

The <code> Tag

Software code warriors have become accustomed to a special style of text presentation for their source programs. The <code> tag is for them. It renders the enclosed text in a monospaced, teletypewriter-style font like Courier familiar to most programmers and readers of O'Reilly's series of books, including this one.

This following bit of en<code>d text is rendered in monospaced font style by Netscape as shown in Figure 4-8.

The array reference <code>a[i]</code> is identical to
the pointer reference <code>*(a+i)</code>.

You should use the <code> tag only for text that represents computer source code or other machine-readable content. While the <code> tag usually just makes text appear in a monospaced font, the implication is that it is source code and future browsers may add other display effects. For example, a programmer's browser might look for <code> segments and perform some additional text formatting like special indentation of loops and conditional clauses. If the only effect you desire is a monospaced font, use the <tt> tag instead.

The <dfn> Tag

Intended to set apart a definition, the <dfn> tag is only supported by Internet Explorer; it is ignored by the other browsers. Nonetheless, we recommend using the <dfn> tag for the reasons you use the other content-based tags: for their meaning, not how some browser formats its enclosed text formatting.

The <em> Tag

The <em> tag tells the client browser to present the enclosed text with emphasis. For nearly all browsers, this means the text is rendered in italic. For example, Mosaic will emphasize by italicizing the words ``always'' and ``never'' in the following sample:

Kumquat growers must <em>always</em> refer to kumquats 
as "the noble fruit," <em>never</em> as just a "fruit."

Adding emphasis to your text is a tricky business. Too little, and the emphatic phrases may be lost. Too much, and you lose the urgency. Like any seasoning, emphasis is best used sparingly.

Although invariably displayed in italic, the <em> tag has broader implications as well and someday browsers may render emphasized text with a different special effect. The <i> tag explicitly italicizes text; use it if all you want are italic. Besides emphasis, also consider using <em> when presenting new terms or as a fixed style when referring to a specific type of term or concept. For instance, one of O'Reilly's book styles is to specially format file and device names. In the HTML version, <em> might be used to differentiate those terms from simple italic for emphasis.

The <kbd> Tag

Speaking of special style for technical concepts, there is the <kbd> tag. As you probably already suspect, it is used to indicate text that is typed on a keyboard. Its enclosed text typically is rendered by the browser in monospaced font style.

The <kbd> tag is most often used in computer-related documentation and manuals, such as in the example,

Type <kbd>quit</kbd> to exit the utility, or type
<kbd>menu</kbd> to return to the main menu.

The <samp> Tag

The <samp> tag indicates a sequence of literal characters that should have no other interpretation by the user. This tag is most often used when a sequence of characters is taken out of its normal context. For example,

The <samp>ae</samp> character sequence may be converted
to the &aelig; ligature if desired.

is rendered by Netscape as shown in Figure 4-9.

(The special HTML reference for the ``ae'' ligature entity is &aelig; and is converted to its appropriate &æ; ligature character by most browsers.) For more information, see Appendix D, Character Entities.

In general, the <samp> tag is not used very often. It should be used in those few cases where special emphasis needs to be placed on small character sequences taken out of their normal context.

The <strong> Tag

Like the <em> tag, the <strong> tag is for emphasizing text, except with more gusto. Browsers display the <strong> tag differently than the <em> tag, usually by bolding the text versus italic, so that users can distinguish between the two. For example,

One should <em>never</em> make a disparaging remark
about the noble fruit. In particular, mentioning 
kumquats in conjunction with vulgar phrases is 
expressly <strong>forbidden</strong> by the Association
bylaws.

the emphasized ``never'' appears in italic with Mosaic, while the <strong> ``forbidden'' is rendered in bold characters (Figure 4-10).

If common sense tells us that the <em> tag should be used sparingly, the <strong> tag should appear in documents even more infrequently. <em> text is like shouting. <strong> text is nothing short of a scream. Like a well-chosen epithet voiced by an otherwise taciturn person, restraint in the use of <strong> makes its use that much more noticeable and effective.

The <var> Tag

The <var> tag, another computer-documentation trick, indicates a variable name or a user-supplied value. The tag is most often used in conjunction with the <code> and <pre> tags for displaying particular elements of computer programming code samples and the like. <var> tagged text typically is rendered in monospace font, as shown in Figure 4-11 of Netscape's display of the following example:

The user should type
<pre>
  cp <var>source-file</var>  <var>dest-file</var>
</pre>
replacing the <var>source-file</var> with the name of 
the source file, and <var>dest-file</var> with the name
of the destination file.

Like the other computer programming and documentation-related tags, the <var> tag not only makes it easy for users to understand and browse your documentation, but automated systems might someday use the appropriately tagged text to extract information and useful parameters mentioned in your document. Once again, the more semantic information you provide to your browser, the better it can present that information to the user.

Summary of Content-based Tags

The various graphical browsers render text inside content-based tags in similar fashion; text-only browsers like Lynx have consistent styles for the tags. Table 4.1 summarizes these browser's display styles.

Table 4-1: Content-based Tags
Tag Netscape Mosaic Internet Explorer Lynx
<cite> italic italic italic monospace
<code> monospace monospace monospace monospace
<dfn> n/a n/a italic n/a
<em> italic italic italic monospace
<kbd> monospace italic monospace bold monospace
<samp> monospace monospace monospace monospace
<strong> bold bold bold monospace
<var> italic italic monospace monospace

Allowed Content

Any content-based style tag may contain any item allowed in text, including conventional text, anchors, images, and line breaks. In addition, other content-based and physical style tags can be embedded within the content.

Allowed Usage

Any content-based style tag may be used anywhere an item allowed in text is used. In practice, this means you can use the <em>, <code>, or other like tags anywhere in your HTML document except inside <title>, <listing>, or <xmp> tagged segments. You can use text style tags in headings, too, but their effect may be overridden by the effects of the heading tag itself.

Combining Styles

It may have occurred to you to combine two or more of the various content-based styles to create interesting and perhaps even useful hybrids. Thus, an emphatic citation might be achieved with:

<cite><em>Moby Dick</em></cite>

In practice, Dr. Frankenstein, the browser usually ignores the monster and, as you can test by typing and viewing the example yourself, Moby Dick gets the citation without emphasis.

The HTML standard does not require the browser to support every possible combination of styles and does not define how the browser should handle such combinations. Someday, maybe. For now, it's best to choose one tag and be satisfied.


Previous Home Next
Changing Text Appearance Book Index Physical Style Tags
 


Banner.Novgorod.Ru