Introduction
Overview
History
Advice
IDE
Books
Tutorials

Beginners
Introduction
Text Formatting
Images
Tables
Forms
Entities/Colors

Advanced
Frames
Image Maps
Stylesheets
Reference

Community
Web Sites
Mailing Lists
USENET
Vendors
News

GBIC >> HTML >> Text Formatting
Text Formatting
It should come as no surprise that a full third of the HTML tags are associated with controlling the way text is displayed. Using these tags a page designer can exercise full control over the font and formatting of text.

HTML text formatting tags come in two flavors - those that specify the exact font attribute desired (font formatting) and those that specify how the text content will be modified relative to the rest of the page content (logical formatting).

In both cases the technique is the same - all text found between a tag pair will be displayed according to the rules of the tag pair.

Font Formatting Logical Formatting


Return to top of document

Font Formatting

The following font formatting tags are defined in the HTML 4.01 specification. To use them, simple place the text to be formatted between the tag pairs. One tag pair can be nested between another to apply more than one attribute to the enclose text (such as bold-italicized text).

    TagDescriptionExample
    <b>:boldThe results are in!
    <font>: font(see example below)
    <i>: italicsThe results are in!
    <s>: strikeoutThe results are in!
    <strike>: strikeoutThe results are in!
    <u>: underlineThe results are in!
    <tt>: teletypeThe results are in!
    <sub>: subscriptThe results are in!
    <sup>: superscriptThe results are in!

Remember to put both the start and end tags around any text that you want to exhibit the results of these tags. If you only put the start tag and leave off the end tag, the tag will take effect all the way to the end of the document.

Of these tags, only the <font> tag supports three attributes. They are listed in the table below along with an example of their effects.

    AttributeCode ExampleResults of Code
    color <font color=red> Hello</font> Hello
    face <font face=Courier> Hello</font> Hello
    size <font size=+2>Hello</font> Hello

The size attribute may be assigned an absolute point size or a relative point size (as in the example above). The color attribute may be assigned one of the pre-named or RGB colors. The face attribute may be one or more font family names, enclosed in quotes. If more than one is entered, the browser users the first one that it comes to which is available on the operating system.

Additionally HTML supports a <basefont> tag that supports the same attributes as the <font> tag. The attributes take effect from the point at which the <basefont> tag is entered in the HTML document, so to affect the entire document place the tag in the document header.

The <basefont> tag may be used muliple times and modifies all subsequent text in the HTML document. Here's an example of the tag:

   <basefont face=Courier size=12 color=blue></basefont>

If this code is placed in the document header, the entire document would use the Courier font, blue color and font-size of 12 points The <basefont> tag pair is unique in that the content of the affected text is not within the tag pair.


Return to top of document

Logical Formatting

The following HTML tags are rendered by the browser with respect to the basefont of the web page document. Except for the <h1> - <h6> tags most of these do not see that much use. Most browsers display these in one of just a few ways: italics, bold, or monospace (all characters the same width). And, since the HTML specification doesn't specify the exact display type, different browsers may renders each of these tags differently so authors tend to use tags that assure them of how the display will appear.

    TagDescriptionExample
    <big>: bigThe results are in!
    <h1>: headers
    (h1-h6)

    The results are in!

    <em>: emphasisThe results are in!
    <strong>: strongThe results are in!
    <ins>: insertedThe results are in!
    <del>: deletedThe results are in!
    <cite>: citationThe results are in!
    <address>: address
    The results are in!
    <samp>: sampleThe results are in!
    <small>: smallThe results are in!
    <code>: codeThe results are in!
    <kbd>: keyboardThe results are in!
    <var>: variableThe results are in!
    <dfn>: definitionThe results are in!

Remember to put both the start and end tags around any text that you want to exhibit the results of these tags. If you only put the start tag and leave off the end tag, the tag will take effect all the way to the end of the document.