Chapter 8

Displaying Text in Lists


CONTENTS


You've probably all heard that one of the best ways to communicate a great deal of information in a short amount of time is by using bulleted lists to convey the message. That philosophy was not lost on the early creators and designers of Web pages, and various tags allow for easy formatting of a number of styles of lists, including both bulleted and nonbulleted incarnations.

Using Lists in HTML

List tags, like paragraphs and preformatted text, are generally HTML containers that are capable of accepting other container and empty tags within their boundaries. These list tags are responsible for affecting the spacing and layout of text, not the emphasis, so they are applied to groups of text, and allow individual formatting tags within them.

Most HTML lists are created following the form:

<LIST TYPE>
<ITEM> First item in list
<ITEM> Second item in list
<ITEM> Third item
</LIST TYPE>

Each of the items appears on its own line, and the <ITEM> tag itself is generally responsible for inserting either a bullet point or the appropriate number, depending on the type of list that's been defined. It's also possible that the <ITEM> tag could insert no special characters (bullets or otherwise), as is the case with definition listings.

You'll look at each type in the following sections. The basics to remember are to use the main container tags for list type and the individual empty tags to announce each new list item. The type of list you choose is basically a question of aesthetics.

Ordered and Unordered Lists

It might be better to think of these as numbered (ordered) and bulleted (unordered) lists, especially when we're talking about their use in HTML. The only drawback to that is the fact that the HTML codes for each suggest the ordered/unordered names. For numbered/ordered lists, the tag is <OL>, and for bulleted/unordered lists, the tag is <UL>. Confused yet? That's my job.

For either of these lists, a line item is designated with the empty tag <LI>. In the case of ordered lists, the <LI> tag inserts a number; for unordered lists, it inserts a bullet point. Examples of both follow. The following is an ordered list:

<OL>
<LI> Item number one.
<LI> Item number two.
<LI> Item number three.
</OL>

And here's an unordered list:

<UL>
<LI> First item.
<LI> Second item.
<LI> Third Item.
</UL>

Once you've got one of these under your belt, the other looks pretty familiar, doesn't it? To see how these look in a browser, check figure 8.1. (Note that I've added a line of text before each to make each list easier to identify.)

Figure 8.1 : The subtle differences between ordered and unordered lists.

As I've already mentioned, both ordered and unordered lists can take different types of internal HTML tags. It's even possible to include paragraph, line break, and header tags in lists.

Note
In the HTML 2.0 standard, it's considered bad form to use the header tags in bulleted lists, since your goal is probably only to change the size of the text for emphasis. Header tags are designed for page organization, not emphasis. Most browsers will interpret them correctly, but you should also stop to consider that they usually look pretty ugly in lists.

While you may see the potential in creating ordered lists that conform to standard outlining conventions (for instance, Roman numerals and letters), HTML 2.0 doesn't really help much. There is no way to change the <LI> number from Arabic numbers, and there's no way in HTML 2.0 to create a list that starts with something other than 1.

Netscape, however, has added both of these abilities, and you can be much freer in your outline, as long as you warn your users ahead of time to view your page with Netscape Navigator (or a Netscape-compatible browser). Refer to Chapter 19 for more on this.

Example: Formatting Within Lists

Different formatting within lists can offer some dramatically different results, and you should take some time to experiment. Load and save your template as a new HTML document, and enter Listing 8.1 (or similar experiments) within the body tags.


Listing 8.1  lists.html  Formatting Example
<BODY>
<P>The following are some of the things that little boys are made of:</P>
<UL>
<LI> Dirt
<LI> Snails
<LI> Puppy-dog <B>tails</B>
<LI> Worms
<LI> Various ramblings from <I>Boy Scout Magazine</I>
<LI> An affinity for volume controls
</UL>
<P> And, in order of importance, here are the things that little girls are made of:</P>
<OL>
<LI><P>An instinctive ability to listen and reason. Although relational in their logic, and often not as <I>spatial</I> and detached in their thinking, a superior empathetic capability general makes little girls better at conflict resolution.<P>
<LI> Outstanding memories. Little girls can remember things like
addresses with little or no difficulty. Consider this long lost professor of my aging mother whose address she can still recall:<BR>
<ADDRESS>
1472 Wuthering Heights Circle<BR>
Poetsville, CT 31001<BR>
</ADDRESS>
She visited once, and his dogs were mean to her.</P>
<LI> The gift of <STRONG>Absolute control</STRONG> over all things sentient.
</OL>
</BODY>

Notice that, in every instance, only a new <LI> tag is capable of creating a new line in the list. Nearly any other type of HTML markup is possible within a given line item. Once you've saved this document, call it up in a browser and notice how it's formatted (see fig. 8.2).

Figure 8.2 : Ordered and unordered lists with special HTML formatting.

Directories, Definitions, and Menus

Your other lists have something in common with one another that they don't share with ordered and unordered lists: all of them use some permutation of the previous line-item system, but none of them consistently use numbers or bullets. Directories and menus are basically just plain lists. Definitions are unique among all lists because they offer two levels of line items within the list structure-one for the definition item and one for the definition itself.

Directory and Menu Lists

To create a directory or menu list, you start with its respective container tag: <DIR> or <MENU>. Of these two, the directory list is probably more useful. Most browsers don't currently render the <MENU> command consistently-some use a bulleted list, others use no bullets. The following is an example of <MENU>:

<MENU>
<LI>House Salad
<LI>Fresh <B>Soup of the Week</B>
<LI>Buffalo Wings
<LI>Escargot
<LI>Liver and Onions
<LI>Turkey Sandwich, <EM>open faced</EM>
<LI>Turkey Sandwich, <EM>pre-fab</EM>
</MENU>

Note
You might use the <MENU> tag when creating a list of hypertext links. It's thought that future interpretations of the menu list may be built into future browsers, and that designers will eventually see more benefit in using the <MENU> tag.

In theory, the <DIR> tag is a little more limiting. It's designed as a mechanism for listing computer file directories in HTML pages. Technically, it doesn't support interior HTML tags, although most browsers will display them. The <DIR> tag is also supposed to be limited to 24 characters (for some unknown reason) and show the filenames in rows and columns, like a DIR/W command in MS-DOS, but the bulk of browsers seems to ignore both of these constraints as well, as in the following example:

<DIR>
<LI> autoexec.bat
<LI> config.sys
<LI> .signature
<LI> .password
<LI> System Folder
<LI> commaand.com
<LI> .kernel
</DIR>

Most browsers (including Netscape) will use the same font and layout for menus and directories as they will for unordered lists. In some cases, browsers will display one or the other (more often directory lists) without a bullet point, which can make them mildly useful. Some browsers can be set to a different font for directories and menus (versus ordered lists). So you may want to use these types, if only because some Web-savvy users' browsers will make an effort to display them differently (see fig. 8.3).

Figure 8.3 : Menu and directory lists in MS Internet Explorer.

Definition Lists

The final list tag is the definition list, which is designed to allow for two levels of list items, originally conceived to be the defined term and its definition. This is useful in many different ways, though, and is also nice for its consistent lack of bullet points or numbering items (as opposed to the menu and directory listings, which are often rendered haphazardly by browsers).

The tags for this list are the container tag <DL> (definition list) and two empty tags, <DT> (definition term) and <DD> (definition). The <DT> tag is designed (ideally) to fit on a single line of your Web page, although it will wrap to the beginning of the next line if necessary. The <DD> tag will accept a full paragraph of text, continuously indented beneath the <DT> term. The following is an example of all three tags:

<DL>
<DT><B>hero</B> <I>(n.)</I>
<DD>A person admired for his or her brave or noble deeds.
<DT><B>hertz</B> <I>(n.)</I>
<DD>A unit used in the measurement of the frequency of electromagnetic waves
<DT><B>hex</B> <I>(n.)</I>
<DD>An evil spell or magical curse, generally cast by a witch.
</DL>

Notice that standard HTML mark-up is permissible within the boundaries of a definition list, and that using bold and italics for the defined terms adds a certain dictionary-like quality (see fig. 8.4).

Figure 8.4 : A basic definition list.

Tip
Not all browsers will display definition lists in the same way, so adding spaces to <DT> items (to get them to line up with the <DD> text) is often a waste of time.

It should also be pointed out that just because definition lists allow for two different types of list items, you needn't necessarily use both. Using just the <DT> tag in your list, for instance, will result in a list not unlike an unordered list-except that nearly all browsers will display it without bullets:

<DL>
<DT>Milk
<DT>Honey
<DT>Eggs
<DT>Cereal
</DL>

And, although more difficult to find a use for, the <DD> item could be used on its own to indent paragraphs repeatedly. This book occasionally uses a similar device.

<P>I must say that I was shocked at his behavior. He was:
<DL>
<DD><I>Rude.</I> Not rude in your standard sort of affable way, or even in a way that would be justifiable were he immensely weathly or critically wounded. It was just a rudeness spilling over with contempt.
<DD><I>Unjust.</I> If there was something he could accuse you of falsely,
he would do it. I could almost see him skulking around his apartment after a particularly unsucessful party, doing his best to find things stolen, which he could blame on people who hadn't actually bothered to show up.
</DL>
</P>

The definition list offers some additional flexibility over the standard lists, giving you more choices in the way you layout the list items (see fig. 8.5).

Figure 8.5 : Definition lists using only one of the two elements.

Example: HTML Within Lists

With the definition list, there are many things you can accomplish with formatting. You can experiment with different HTML tags to see how they react within the list. Remember that, within the <DL> and </DL> tags, the two data item tags, <DT> and <DD>, reign supreme. For instance, even a new paragraph within a <DD> tag will stay indented in most browsers.

Load your template and choose the Save As command to give it a new name. Then type Listing 8.2 between the body tags (see fig. 8.6).

Figure 8.6 : Using extensive HTML formatting in a list.


Listing 8.2  lists2.html  HTML Within Lists
<BODY>
<H1>Computer Terms</H1>
<DL>
<DT><B>CPU</B>
<DD>Central Processing Unit. This is the "brain" of a computer, where
instructions created by the computers system software and application
software are carried out.
<DT><B>Hard Drive</B>
<DD>Sometimes called a <I>fixed drive</I>, this is a device (generally
mounted inside a computer's case) with spinning magnetic plates that is
designed to store computer data. When a file is "saved" to the hard drive, it is available for accessing at a later time.<BR>
Most system software and application programs are also stored on the
computer's internal hard drive. When an applications name is typed or icon is accessed with a mouse, the application is loaded from the hard drive in RAM and run by the system software.
<DT><B>Application Software</B>
<DD>Computers programs used to create or accomplish something on a computer, as distinct from system software. Examples of computer application software might include:<BR>

WordPerfect (a word processing application)<BR>
Microsoft Excel (a spreadsheet application)<BR>
QuarkXPress (a desktop publshing application)<BR>
Corel Draw (a computer graphics application)<BR>
</DL>
<BODY>

Using the <BR> tag allows you to create an impromptu list within the list, although everything remains indented because it's ultimately under the influence of the <DD> tag. The definition item tags (<DT> and <DD>) stay in effect until another instance of a definition item tag is encountered or until the </DL> tag ends the definition list.

Nesting Tags and Combining List Types

Since most of your HTML lists can accept HTML tags within their list items, it stands to reason that you could potentially create lists within lists. In fact, creating a list, then creating another list as part of an item in that first list is how you can create an outline in HTML.

Nesting Tags

The idea of nesting comes to us from computer programming. Nesting is essentially completing an entire task within the confines of another task. For HTML, that means completing an HTML tag within the confines of another container tag. This could be something like the following:

<P>She was easily the most <EM>beautiful</EM> girl in the room.</P>

This is an example of correctly nesting the <EM> tag within a paragraph container. On the other hand, many browsers would still manage to display this next code:

<P>She was easily the most <EM>beautiful</P> girl in the room.</EM>

But this second example is really poorly constructed HTML. It often works, but the <EM> tag isn't properly nested inside the <P>. In this example, that doesn't matter too much, since you can still reason out what this statement is trying to do.

With lists, however, things can get complicated. So it's best to remember the "nesting" concept when you begin to add lists within lists. As far as HTML is concerned, a nested list works as marked-up text within the previous list item. When the next list item is called for, HTML moves on.

Lists Within Lists

Let's look at an example of a simple nested list:

<OL>
<LI>Introduction
<LI>Chapter One
     <OL>
     <LI> Section 1.1
     <LI> Section 1.2
     <LI> Section 1.3
     </OL>
<LI>Chapter Two
</OL>

Tip
It's a good idea to indent nested lists as shown in the example. The browser doesn't care-it's just easier for you (or other designers) to read in a text editor. (Regardless of your spacing, most browsers will indent the nested lists-after all, that's the point.)

Notice that the nested list acts as a sublevel of the Chapter One list item. In this way, you can simulate an outline in HTML. Actually, the nested list is just HTML code that is part of the <LI>Chapter One list item. As you saw in Listing 8.2, you can use the <BR> tag to create a line break in a list element without moving on to the next list item. Following the same theory, an entire nested list works as if it's a single list item in the original list.

The following:

<OL>
<LI>Section Five<BR>
   This section discusses ducks, geese, finches and swans.
<LI>Section Six
</OL>

is essentially the same as the list that follows:

<OL>
<LI>Section Five
     <OL>
     <LI> Ducks
     <LI> Geese
     <LI> Finches
     <LI> Swans
     </OL>
<LI> Section Six
</OL>

In both cases, the nest HTML container is simply a continuation of the first list item. Both the text after the <BR> in the first example and the ordered list in the second example are part of the list item labeled Section Five. That list item is over when the next list item (Section Six) is put into effect (see fig. 8.7).

Figure 8.7 : In both of the examples, the HTML container is simply part of the list.

Combining List Types

When nesting lists, it's also possible to nest different types of lists within one another. This is useful when you'd like to vary the types of bullets or numbers used in an outline form. For instance:

<OL>
<LI>Introdution
<LI>Company Financial Update
    <UL>
    <LI>First Quarter
    <LI>Second Quarter
    <LI>Third Quarter
    <LI>Fourth Quarter
    </UL>
<LI>Advertising Update
    <UL>
    <LI>Results of Newspaper Campaign
    <LI>Additions to Staff
    <LI>New Thoughts on Television
    </UL>
<LI>Human Resources Update
</OL>

There's nothing terribly difficult to learn here-just the added benefit of being able to nest different types of lists within others. You're still simply adding HTML markup code to items in the original list. This time, however, you have more choice over how your outline looks (see fig. 8.8).

Figure 8.8 : Nesting different types of lists.

Example: Nesting Definition Lists

Although creating outlines is nice, more often you're interested in presenting actual information on your Web pages. Doing that in an outline form can often be helpful to your Web users. You have a number of different ways you can do that, including nesting paragraphs within ordered and unordered lists. Or you can just use definitions lists.

Load your template and choose the Save As command to rename it. Then enter the following text between the body tags:

<BODY>
<H2>About Our Company</H2>
<OL>
<LI>Our Leaders
     <DL>
     <DT><B>Richard B. McCoy, CEO</B>
     <DD> Raised on small farm in Indiana, Dr. McCoy dreamed of something
bigger. By the time he'd graduated from Harvard Business School with an MBA, he'd already realized part of his dream. He'd married the most beautiful woman he'd ever met and was the proud father of a baby girl. From there, his life took control of his career, and his new found interest in parenting launched his idea of building the better baby bed. His invention, the SleepMaker 3000, was an instant success. Twenty years later, he finds his family room couch is enough incentive for him to take a long nap on Saturdays after a good morning round of golf.
     <DT><B>Leslie R. Gerald, CFO</B>
     <DD> Denying the fact that she's an accountant is nearly a full-time
pursuit for Ms. Gerald. Having graduated at the top of her class at Northwestern University, her life has been about 1/3 accounting, 1/3 daredevil athleticism and 1/3 sleep. In the meantime she's found time for a steady beau, decorating her mountain retreat and writing a book called <I>It's More Exciting Than You Think </I> about, believe it or not, flying ultra-light aircraft.
     <DT><B>David W. Deacon, VP of Marketing</B>
     <DD> Known as "Dave" to anyone he's ever spoken to for more than five minutes, Mr. Deacon displays the calm friendliness of the consummate salesman, with a twist. He actually is a nice guy. When he's not doing his best to promote our products, Dave is well known in the community as a service volunteer. Last year he was awarded Seattle's prestigous Man of the Year award in recognition of over 500 volunteer hours and over $50,000 in personal contribution to various area charities.
     </DL>
      <BR>
<LI>Employees of the Month
     <UL>
     <LI> January: Bill Cable, IS
     <LI> February: Janet Smiles, Marketing
     <LI> March: Rich Lewis, Finance
     <LI> April: Wendy Right, Vendor Relations
     <LI> May: Alice Cutless, Area Sales
     <LI> June: Dean Wesley, Training
     </UL>
</OL>
</BODY>

Combining different types of lists, then, is a great way to organize your Web site in such a way that it's easy to get at interesting information. At the same time, it's still possible to present that information in many different ways using various list tags (see fig. 8.9).

Figure 8.9 : Nesting and combining the various types of HTML lists.

Summary

HTML lists are an effective way to communicate a great deal of information in a relatively small amount of space. HTML provides tags for both ordered (numbered) lists and unordered (bullet-style) lists. In addition to those, you can add menu lists, directory lists, and definition lists.

The ordered and unordered lists are easily the most commonly used, while the menu and directory lists don't often add much value to your Web pages. Definition lists, however, are unique because they allow you to have two different types of list items with the lists-a term and its definition.

All of these lists can be used together in what's called nesting, or creating lists within other lists. The definition list is especially good for this because you can add all different types of lists (such as bullet and numbered lists) within the descriptions in your definition list.

It's also possible to nest different types of lists within numbered lists to create multilevel outlines in your HTML documents.

Review Questions

  1. What are the two basic tags in an HTML list?
  2. What does a <LI> create when used in an unordered list?
  3. Can you change the style of numbers in an ordered list (using HTML 2.0 standards)?
  4. Which is less likely to display with bullet points-a directory list or a
    menu list?
  5. Can you use other HTML tags (such as <B> or <EM>) within HTML list containers?
  6. What is unique about the definition list style?
  7. Do definition lists have to be used for words and their definitions?
  8. Does HTML force you to include both a <DT> and a <DD> tag in your definition lists?
  9. Is nesting something that happens only in HTML lists?
  10. Which of these is an example of a nested list?
    (A)

    <OL>
    <LI>Groceries<BR>
        Milk<BR>
        Soup<BR>
        Ice Cream<BR>
    <LI>Other groceries
    </OL>

    (B)
    <OL>
    <LI>Groceries
       <UL>
       <LI> Milk
       <LI> Soup
       <LI> Ice Cream
       </UL>
    <LI>Other Groceries
    </OL>
  11. What type of HTML lists would you use to create an outline, the major points of which were numbered and the minor points used bullets?

Review Exercises

  1. Create a list using the <DIR> and <MENU> tags. View each in your different browser and note how some browsers render these differently from one another.
  2. Create a <DL> definition list with nothing but <DD> elements, and one with nothing but <DT> elements. Notice how they're rendered in your browser. Definition lists used in this way are often very useful.
  3. Use nested definition lists to create your own HTML "outline." You can use the <DL> elements to number your own outline elements, like the following:

    <DL>
    <DT> I. Introduction
       <DL>
       <DT> A. Welcome!
       <DT> B. Description of Mission Statement
       <DT> C. Conventions in this Report
       </DL>
    <DT> II. Chapter One
    </DL>