HTML: The Definitive Guide

Previous Chapter 4 Next
 

4.6 Expanded Font Handling

Netscape Navigator and Internet Explorer have features beyond HTML 2.0 that give you more explicit control over the colors and sizes of the font characters that form your HTML text. Explorer even has a way for you to specify the display font itself.

Don't get overly excited, though. The font extensions and conventions don't override standard HTML. Header tags and their respective effects on font size still work. So do the various physical tags like <b> and <i>. With fonts, the extensions truly are extensions, not revisions.

The Extended Font Size Model

Instead of absolute point values, Netscape and Internet Explorer use a relative model for sizing fonts. Ranging in size from 1, the smallest, to 7, the largest, the default (basefont) font size is 3.

It is almost impossible to reliably state the actual font sizes used for the various virtual sizes. Most browsers let the user change the physical font size, and the default sizes vary from browser to browser. It may be helpful to know, however, that for the fonts-extended browsers, each virtual size is successively 20 percent larger or smaller than the default font size 3. Thus, font size 4 is 20 percent larger, font size 5 is 40 percent larger, and so on, while font size 2 is 20 percent smaller and font size 1 is 40 percent smaller than font size 3.

The <basefont> Tag

The <basefont> tag lets you define the basic size for the font that Netscape Navigator and Internet Explorer use to render normal document text.

The <basefont> tag has a single required attribute, size, whose value determines the document's base font size. It may be specified as an absolute value from 1 to 7, or as a relative value by placing a plus or minus sign before the value. In the latter case, the base font size is increased or decreased by that relative amount. The default base font size is 3.

Authors typically include the <basefont> tag in the head of an HTML document, if at all, to set the base font size for the entire document. Nonetheless, the tag may appear nearly anywhere in the document, and it may appear several times throughout the document, each with a new size attribute. With each occurrence, the <basefont> tag's effects are immediate and hold for all subsequent text.

In an egregious deviation from the HTML and SGML standards, the ending </basefont> tag does not terminate the effects of the most recent <basefont> tag. Instead, the </basefont> end tag resets the base font size to the default value of 3, which is the same as writing <basefont size=3>.

The following example source and Figure 4-13 illustrate how Netscape responds to the <basefont> tag and </basefont> end tag, including fixed and relative attribute values:

Unless the base font size was reset above,
Netscape renders this part in font size 3.
<basefont size=7>
This text should be rather large (size 7).
<basefont size=-1> Oh, 
<basefont size=-1> no! 
<basefont size=-1> I'm 
<basefont size=-1> shrinking!
</basefont>
Ah, back to normal.

The <font> Tag

The <font> tag lets you change the size, style, and color of text. It should be used like any other physical or content-based style tag for changing the appearance of a short segment of text.

To control the color of text for the entire document, see the special extension attributes for the <body> tag described in Chapter 5.

The size attribute

The value of the size attribute must be one of the virtual font sizes (1-7) described earlier, defined as an absolute size for the enclosed text or preceded by a plus or minus sign (+ or -) to define a relative font size that Netscape Navigator or Internet Explorer adds to or subtracts from the base font size (see the <basefont> tag above). The extended browsers automatically round the size to 1 or 7 if the calculated value exceeds either boundary.

In general, use absolute size values when you want the rendered text to be an extreme size, either very large or very small, or when you want an entire paragraph of text to be a specific size.

For example, using the largest font for the first character of a paragraph makes for a crude form of illustrated manuscript (see Figure 4-14):

<p>
<font size=7>C</font>all me Ishmael.

Also use an absolute font when inserting a delightfully unreadable bit of ``fine'' print--boilerplate or legalese--at the bottom of your documents (Figure 4-15):

<p>
<font size=1>
All rights reserved. Unauthorized redistribution of this document is 
prohibited. Opinions expressed herein are those of the authors, not the 
Internet Service Provider.

Except for the extremes, use relative font sizes to render text in a size different than the surrounding text, to emphasize a word or phrase, for example (see Figure 4-16):

<p>
Make sure you <font size=+1>always</font> sign and date the form!

If your relative size change results in a size greater than seven, Netscape uses font 7. Similarly, font sizes less than one are rendered with font 1.

Notice that, with Netscape, specifying size=+1 or size=-1 is identical in effect to the alternate tags, <big> and <small> respectively. However, nested relative changes to the font size are not cumulative as they are for the alternate tags. Each <font> tag is relative to the base font size, not the current font size. [<big>, 4.5.2]

For example (see Figure 4-17):

<p>
The ghost moaned, "oo<font size=+1>oo<font size=+2>oo<font 
size=+3>oo</font>oo</font>oo</font>oo."

Contrast this with the <big> tag, which increases the size one level as you nest the tags.

The color attribute

The color attribute for the <font> tag sets the color of the enclosed text. The value of the attribute may be expressed in either of two ways: as the red, green, and blue (RGB) components of the desired color or as a standard color name. Enclosing quotes are recommended, but not required.

The RGB color value, denoted by a preceding hash mark (#), is a six-digit hexadecimal number. The first two digits are the red component, from 00 (no red) to FF (bright red). Similarly, the next two digits are the green component and the last two digits are the blue component. Black is the absence of color, #000000; white is all colors, #FFFFFF.

For example, to create basic yellow text, you might use:

Here comes the <font color="#FFFF00">sun</font>!

Alternatively, you may set the enclosed font color using any one of the many standard color names. See Appendix E, Color Names and Values, for a list of common ones. For instance, you could also have made the above sample's text yellow with the following source:

Here comes the <font color=yellow>sun</font>!

The face attribute

Internet Explorer lets you change the font style in a text passage with the face attribute for the <font> tag.[1] The quote-enclosed value of face is one or more display font names separated with commas.

[1] For the HTML purist, for the once-powerful user, who had ultimate control over their browser, this is egregious, indeed. Form over function; look over content--what next? Embedded video commercials you can't stop?

The font face displayed by the browser depends on which fonts are available on the individual user's system. The browser parses the list of font names, one after the other, until it matches one with a font name supported by the user's system. If none match, the text display defaults to the font style set by the user in their browser's Preferences.

For example:

This text is in the default font. But, 
<font face="Braggadocio, Machine, Zapf Dingbats">
heaven only knows</font>
what font face is this one?

If the Internet Explorer user has the Braggadocio, Machine, or none of the listed font typefaces installed in their system, they will be able to read the ``heaven only knows'' message in the respective or default font style. Otherwise, the message will be garbled because the Zapf Dingbats font contains symbols, not letters. Of course, the alternative is true, too; you may intend that the message be a symbol-encoded secret.


Previous Home Next
Physical Style Tags Book Index Precise Spacing and Layout