HTML: The Definitive Guide

Previous Chapter 8
Formatted Lists

8.2 Ordered Lists

Use an ordered list when the sequence of the list items is important. A list of instructions is a good example, as are tables of content and lists of document footnotes or endnotes.

The <ol> Tag

The typical browser formats the contents of an ordered list just like an unordered list, except that the items are numbered instead of bulleted. The numbering starts at one and is incremented by one for each successive ordered list element tagged with <li>. [the section called "The <li> Tag"]

HTML 3.2 has a number of features that provide a wide variety of ordered lists. You can change the start value of the list and select any of five different numbering styles. Here is a sample ordered list:

<h3>Pickled Kumquats</h3>
Here's an easy way to make a delicious batch of pickled 'quats:
  <li>Rinse 50 pounds of fresh kumquats
  <li>Bring eight gallons white vinegar to rolling boil
  <li>Add kumquats gradually, keeping vinegar boiling
  <li>Boil for one hour, or until kumquats are tender
  <li>Place in sealed jars and enjoy!

This is rendered by Netscape as shown in Figure 8.2.

The start attribute

Normally, browsers automatically number ordered list items beginning with the Arabic numeral 1. The start attribute for the <ol> tag lets you change that beginning value. To start numbering a list at 5, for example:

<ol start=5>
  <li> This is item number 5.
  <li> This is number six!
  <li> And so forth...

The type attribute

By default, browsers number ordered list items with a sequence of Arabic numerals. Besides being able to start the sequence at some number other than 1, you can use the type attribute with the <ol> tag to change the numbering style itself. With the <ol> tag, the type attribute may have a value of "A" for numbering with capital letters, "a" for numbering with lowercase letters, "I" for capital Roman numerals, "i" for lowercase Roman numerals, or "1" for common Arabic numerals. (See Table 8.1).

Table 8.1: HTML 3.2 type values for numbering ordered lists
Type Value Generated Style Sample Sequence
A Capital letters A, B, C, D
a Lowercase letters a, b, c, d
I Capital Roman numerals I, II, III, IV
i Lowercase Roman numerals i, ii, iii, iv
1 Arabic numerals 1, 2, 3, 4

The start and type attribute extensions work in tandem. The start attribute sets the starting value of the item integer counter at the beginning of an ordered list. The type attribute sets the actual numbering style. For example, the following ordered list starts numbering items at 8, but because the style of numbering is set to i, the first number is the lowercase Roman numeral, "viii." Subsequent items are numbered with the same style, each value incremented by 1 as shown in this example:

<ol start=8 type="i">
  <li> This is the Roman number 8.
  <li> The numerals increment by 1.
  <li> And so forth...

The results are shown in Figure 8.3.

The type and value of individual items in a list can be different from the list as a whole, as described in 3.1.

Compact ordered lists

Like the unordered list, the ordered list in HTML has an optional compact attribute. When instructed to compact the ordered list, the browser may reduce the indentation, reduce the amount of space between the sequence numbers and the list items, or both. Some browsers cannot compact and so do nothing.

The style and class attributes

The style attribute for the <ol> tag creates an inline style for the elements enclosed by the tag, overriding any other style rule in effect. The class attribute lets you format the content according to a predefined class of the <ol> tag; its value is the name of that class. [the section called "Inline Styles: The style Attribute"] [the section called "Style Classes"].

Previous Home Next
Unordered Lists Book Index The <li> Tag

HTML: The Definitive Guide CGI Programming JavaScript: The Definitive Guide Programming Perl WebMaster in a Nutshell
This HTML Help has been published using the chm2web software.