Lists may seem to be mundane items, but many pages on the Web include at least one. The way you choose to mark up these lists can make a big difference. This article explores several the advantages and disadvantages of several common markup methods. It is taken from chapter one of Dan Cederholm's book Web Standards Solutions: The Markup and Style Handbook (Apress, 2004; ISBN: 1590593812).
Lists. They’re found in just about any page on the Web. Lists of hyperlinks, lists of items in a shopping cart, lists of your favorite movies—even lists for the navigation of an entire website. While it might seem arbitrary to some, how we mark up these lists is what we’ll explore, discovering the advantages (and disadvantages) of a few common methods. Later, we’ll put those advantages to the test with several examples on how to style an ordinary list.
Let’s go shopping
Initially, I thought about using a laundry list as the example for the chapter, but then quickly realized that I have no idea what items would be included in such a list. So for this example’s sake, groceries it is . . .
Let’s imagine that you needed to mark up a simple grocery list for inclusion on your personal website. You may be wondering what place a grocery list has on any website, but that’s beside the point. We just need a reason to start thinking about lists.
On the page, say we’d like the grocery list to look like . . . well, a list—a vertical series of items, each on their own line:
Apples Spaghetti Green Beans Milk
A seemingly simple task, right? Now, like all facets of web design and development, there are a variety of ways we could attack this to achieve the same (or similar) results. As in all examples found throughout this book, I’ll be presenting things from an eXtensible Hyper TextMarkup Language (XHTML) point of view—making sure that the methods chosen are valid markup and adhere to the standards outlined by the World Wide Web Consortium (W3C, www.w3.org/).
We could simply add a <br /> tag after each item and be done with it, or we could tap into various list elements to get the job done. Let’s look at three different possibilities, and the consequences of using each of them.
This chapter is from Web Standards Solutions: The Markup and Style Handbook by Dan Cederhold (Apress, 2004, ISBN: 1590593812). Check it out at your favorite bookstore today. Buy this book now.