Archive for September, 2003

Accessible Image-Tab Rollovers

I recently implemented a new navigation system for Fast Company and thought it’d be useful to document the process.

The Problem

We needed to fit more items into FC’s top navigation. We ran out of room. Previously, this was handled by a simple, styled unordered list. But at a window resolution of 800×600 there wasn’t enough additional horizontal space to add even one more item using the current design.

The Solution

I choose to combine and modify Pixy’s brilliant Fast Rollovers and Stuart Langridge’s accessible image replacement technique to create accessible, Javascript free, image-tab rollovers.

How does it work?

The XHTML: One List to Rule Them All

I wanted to continue to use a simple unordered list for the navigation in the markup. Much has already been said about using lists for navigation, here and elsewhere. They’re compact, lightweight and accessible to text browsers, screenreaders, PDAs, phones, etc.

Here’s what the list looked like originally (I’ve deleted some of the actual items to make it more convenient to demonstrate):

<ul id="nav">
<li><a href="/" class="selected">Home</a>&lt/li>
<li><a href="/guides/">Guides</a>&lt/li>
<li><a href="/magazine/">Magazine</a>&lt/li>
<li><a href="/articles/">Archives</a>&lt/li>

Nice and simple. Now let’s add a unique id to each li so that we can do some fancy stuff with it (namely, replace the boring text with stylized tabs):

<ul id="nav">
<li id="thome"><a href="/" class="selected">Home</a>&lt/li>
<li id="tguides"><a href="/guides/">Guides</a>&lt/li>
<li id="tmag"><a href="/magazine/">Magazine</a>&lt/li>
<li id="tarchives"><a href="/articles/">Archives</a>&lt/li>

Now we’re ready to create some tab images.

One Image, 3 States

The essence of Pixy’s Fast Rollovers involves creating one image for each navigation item that includes normal, hover and active states stacked on top of each other. Later, we’ll use CSS to change the background-position to reveal each state at the appropriate time.

fig. 1
Figure 1.1

Figure 1.1 on the right shows an example image that I’ve created and used for Fast Company’s new navigation. Each state is 20px tall with a total image height of 60px. The top 20px is the normal state, the next 20px shows the hover state and final 20px shows the active state (which is also used for the “you are here” effect). There are similar images for each tab we’d like to use.

Using one image for each state allows us to toss out ugly Javascript and instead make use of simple CSS rules for hover effects. This is good. It also eliminates the “flicker” effect that other CSS methods suffer from, where separate on/off images are used. This is good. We also don’t have to pre-load any additional images. Again… this is good.

The CSS: This is Where the Magic Happens

First we’ll set up the rules that all navigation items will need. This will save us from writing duplicate rules for each tab. Then we’ll add a separate rule for each list item id, giving the li it’s own background-image and width — the only two variables that will be different for each tab.

The CSS goes something like this:

#nav {
margin: 0;
padding: 0;
height: 20px;
list-style: none;
display: inline;
overflow: hidden;
#nav li {
margin: 0;
padding: 0;
list-style: none;
display: inline;
#nav a {
float: left;
padding: 20px 0 0 0;
overflow: hidden;
height: 0px !important;
height /**/:20px; /* for IE5/Win only */
#nav a:hover {
background-position: 0 -20px;
#nav a:active, #nav a.selected {
background-position: 0 -40px;

This essentially turns off padding and list styles, makes the list horizontal and hides the text that’s between each hyperlink in the list. Notice the :hover and :active rules. These are generic for every a element within #nav so that we don’t have to repeat those particular rules for each item.

I’ve also assigned a “selected” class to a tab that I wish to highlight permanently, signifying which section of the site you are currently on. This is shared with the :active state.

You may also notice that list-style: none; and display: inline; are repeated in both the #nav and #nav li selectors. This was to keep IE5/Win happy. In a perfect world, declaring this once for #nav would be perfectly sufficient. That’s not the case, of course.

Next, we’ll add the rule for each id and assign it’s background-image and width. Here’s an example:

#thome a  {
width: 40px;
background: url(home.gif) top left no-repeat;

There’s a similar declaration for each tab needed.

The Results

fig. 2
Figure 1.2

Figure 1.2 shows the resulting tabs in normal, hover and selected state. To see it all working in action, check out the working example with sourcecode, or better yet, the real-world implementation at

Why use it?

  • It’s lightweight: Just an unordered list in the markup.
  • It’s accessible: Using Stuart’s method, we can insure screenreaders will read the text links.
  • No Javascript: We don’t need to pre-load or create multiple images for each state. We also don’t need extra Javascript to control hover effects. Thanks, Pixy.
  • It’s stylized: Fitting hypertext into defined areas can be tricky, this allows for using stylized images.

But Wait, the Text Doesn’t Scale!

Following a great suggestion from Doug Bowman, and in response to legibility issues and the inability to resize image text, I went a step further and created second set of tab images with larger text labels. I could then override rules on the exisiting “medium” and “large” alternate stylesheets. The alternate styles are activated using Paul Sowden’s Stylesheet switcher.

An example of the overriden rule looks almost identical to the original, with a new width and image path:

#thome a  {
width: 46px;
background: url(guides_lg.gif) top left no-repeat;

fig. 3
Figure 1.3

Figure 1.3 shows the larger tabs as they appear on Fast Company, where you’ll notice that the horizontal spacing is tighter while the vertical size remains the same as the original. But, by adding the ability to increase the size of hypertext as well as the tab images we’ve helped out low vision users, while still working with our certain design constraints. Thanks to Doug for this solution.


Tested and working in Windows: Mozilla, Netscape7, IE5.0+; Mac: Mozilla, Camino, IE5, Safari.

Specifically for Fast Company, I choose to position: absolute the #nav in order to make things line up perfectly, letting the background color of the header area show through underneath. This works fine and dandy — except in Opera7/Win where specifying a width is necessary for absolutely positioned elements (ugh). That’s OK though, we’ll just add the total width of the images (added up) to the #nav:

#nav {
margin: 0;
padding: 0;
height: 20px;
list-style: none;
display: inline;
overflow: hidden;
width: 201px;

Now we can sleep at night, and Opera fans rejoice.

Special thanks to Paul Maiorana for letting me bounce ideas off of him (repeatedly) at the office.

About the Talking About Semantics

I feel the need to take a time-out and regroup in regards to the SimpleQuiz.

What’s the point in arguing about semantics? XHTML is not a semantic language.

I agree — it may never be a purely semantic language. I sort of wished I had never used the word “semantic” in the questioning of the quizzes. What we’re trying to get at here is whether one method of markup has any benefits over another. That’s it. Call it semantics, call it preferred methods, call it advantages and disadvantages, etc. The bottom line is that talking about this stuff (as mundane and ridiculous as it can get) can be beneficial.
Sure, at times we’re all splitting hairs and to some it may seem like an absolute waste. But, call me crazy, it’s fun talking about the million different ways to markup a list or a form or a heading — and hearing how others may do it differently. I also hope to broaden the questions to handle CSS methods and tricks.
So, the intention is to question the whole idea of semantics, when they’re helpful or when they ain’t — not to preach some “golden way” of writing web pages. I’ll be the last to want to adhere to a single way of marking up XHTML. Sometimes, a tag is a tag is a tag, and instead of worrying about what’s right we should go outside and toss the football around (or kick the football around for all you non-Americans).
Allright. Had to get that off my chest. Now back to work. The next quiz will be on how XHTML files with odd numbered byte sizes are more semantically correct. (Just kidding).

SimpleQuiz › Titles › Conclusion (sort of)

Where do I begin? This one has no obvious answer, and didn’t really intend to. In fact, very few of these questions really intend to have a definitive answer. And the following is my attempt to absorb the illuminating comments (and they are always illuminating) and make some sense of them.

Let’s get right to it. Book titles. Right. The title of a book. Think about seeing a book title in print — in a magazine or another book. A book title is normally set in italics. It’s a visual clue. It’s strictly presentational. Now think about a book title on a web page. We still want that visual clue — italics, but we also want all browsers and devices to know that this is a book title as well.

Moby Dick. I just used i. Is that any good? Well, using i is strictly presentational, it’ll give us the italics we want, which is good. But:

The only real difference is that i‘s nomenclature disregards all but visual browsers. (full comment)

When using i, visual browsers will render the book title in italics, but others may not.

Looks like B is out.

But non-visual browsers will recognize em you say? Great! But, do you really want the the title of a book to be emphasized (read faster and/or louder)? Probably not, so A is out — although I’m plenty guilty of using it.

So what about cite? Many dispute the relationship of cite in regards to a book title — if you’re simply stating the title of a book, are you really citing it? I suppose I could go either way on that one. One could argue that you are, in fact, citing the book title even when stating it without following quotations. cite also has the benefit of being rendered in italics in most (?) browsers — by default and without additional CSS rules. How many I could not tell you definitively, and that would be an interesting tidbit of information.

A fourth option would be to create a custom class and attach it to the span tag such as <span class="title">This is a Book Title</span>. But this to me is the same as using i — strictly presentational and if you wanted to be hilariously ridiculous you might point out that it would cost you a few more bytes for the span tag and associated CSS rule. Silly, but…

So the moral of this quiz question is: use one of the four methods and move on. Each of them has their respective advantages and drawbacks. Take those into account in the real world, make a choice and feel good in knowing that you may have some extra information on why you made it.

SimpleQuiz › Part VIII › Titles

With this question (based on a suggestion by Shaun Inman), I’m hoping the discussion touches on a few different things that happen to be going on.

I’ll leave it at that for now, and let you all weigh in.

Q: When marking up a book title or publication, which of the following is the best choice?

  1. <p>My upcoming book, <em>SimpleQuiz: Get Down With Markup</em>, will be a bestseller.</p>
  2. <p>My upcoming book, <i>SimpleQuiz: Get Down With Markup</i>, will be a bestseller.</p>
  3. <p>My upcoming book, <cite>SimpleQuiz: Get Down With Markup</cite>, will be a bestseller.</p>

SimpleQuiz › Order Up › Conclusion

Looking over the comments from the question, it appears that most saw either A or B as semantically equal. Adam Polselli brought up an interesting point though on a possible benefit to choosing option A:

I think that there’s an advantage to using A. If you style your links as “font-weight: normal“, then having the <a> tag inside the <strong> tag would override <strong>‘s “bolding.”

Certainly that is something to think about, even when either order would work for you.

Good arguments were presented for either method, with some pointing to whether the link itself needed strong emphasis or just the text contained.

I’ll admit, I’m feeling a little lazy with writing this wrap-up — not because the discussion for this one was any less illuminating, but because there were many, for lack of a better term, thought provoking comments making a case for either order. Just read through these. Class dismissed.

Read all quiz questions and conclusions.

Copy Protection? Boo.

I’ve just purchased The Darkness new album, Permission to Land — it’s a great one, conjuring up rock’s past masters of the late 70s and early 80s. We’re talking Journey, Boston, Foreigner and Loverboy here.
Anyhow, the band is beside the point — this was the first CD I’ve purchased that has some sort of bogus copy protection built into it. Crap. Now I can’t play it on my Mac and I can’t rip it to live on my iPod. Ridiculous. There was no warning on the packaging about it being copy protected. Now I’m not sure of what to do with it. Return it? Then I have no way of listening to the 100% pure rock of the Darkness.
Has anyone else run into this dilemma?

SimpleQuiz › Part VII › Order Up

This quiz focuses on element ordering, and is based on a suggestion from Paul Smith. When hyperlinks are coupled with inline phrase elements (such as strong, em, abbr, etc.) are there any consequences in regards to the ordering?

Q: Which of the following is more semantically correct, and are there advantages to either method?

  1. <a href=""><strong>The Greatest Web Site Ever</strong></a>
  2. <strong><a href="">The Greatest Web Site Ever</a></strong>

List-o-matic: It’s Just Too Easy Now

Ian Lloyd over at just made creating CSS-based navigation lists incredibly simple.
List-o-matic (not to be confused with it’s excellent inspiration, Listamatic) is a wizard for quickly creating unordered navigation lists, while allowing you to choose from a few different CSS styles, such as my Mini-Tabs and others.
Enter a few link names and URLs, choose a style and … bingo. You have yourself some styled navigation. It doesn’t get any easier than this.
Oh, and YARRR!

SimpleQuiz › Form(atting) › Conclusion

This was a tough one to wrap up. There are probably more acceptable possibilities with this question than with previous questions. A lot of great examples were brought to light regarding label and fieldset elements.

Notable Comments

Simon Willison:

…once I start working with forms I switch my focus from semantics to accessibility and usability.

Excellent point. It’s always good practice to ask yourself whether you’re being semantic for the sake of being semantic. Have I mentioned that I don’t like the actual word “semantic”? I don’t.


I don’t really consider a form label and text field a paragraph so that’s out.

This was echoed through the rest of the discussion as well. However, it just might give you better results in the nonstyled version (as opposed to using a
div or label or nothing).

And while using nothing might not appeal to you, MikeyC pointed out that it will not validate without a block-level element surrounding the label.

Which brings us to using fieldset, which Dave S. first suggested. The use of fieldset opened the floodgates on a host of great examples, and for simple small forms, fieldset and some CSS applied might be all you really need.

The use of fieldset was also argued a bit, back and forth. On one hand, you could see this as purely a presentational addition, and on the other hand you could quote the W3C:

The FIELDSET element allows authors to group thematically related controls and labels. Grouping controls makes it easier for users to understand their purpose while simultaneously facilitating tabbing navigation for visual user agents and speech navigation for speech-oriented user agents. The proper use of this element makes documents more accessible.

I like the sound of that.

You can’t talk about forms without talking about using table to format them. Paul G.:

… it ensures that labels and inputs maintain a logical visual order and layout when CSS is off

Certainly for larger forms, when you’re dealing with multiple controls, inputs, form fields, drop-downs, etc. — tables still seem like the best way to go. You could argue either way, whether a form is tabular data — but the truth is, styling a large form soley with CSS is not a simple task, and undoubtedly will not degrade nicely.

Summary (my take)

When it comes to marking up forms, I’ll take the following into account:

  • When marking up a small form with a few elements, I’ll use fieldset and CSS to style them — taking into account what the unstyled form will look like.
  • Tables still are not evil. For large forms, in order to make the form useable and organized, it’s hard to beat the simplicity of a table here. CSS techniques seem to be somewhat complicated in a place where a simple table would work all around.
  • In the past, I’ve used p tags to group label and matching input tags. I’m now divided on this method. For simple forms, it will ensure consistent formatting across browsers yet could be argued that it is not a paragraph of text.
  • Trying to semantically structure a form makes my head hurt.

See all quiz questions and discussions in chronological order.

SimpleQuiz › Part VI › Form(atting)

Let’s talk forms. A lot my web design headaches are caused while formatting form items. This quiz question comes to us from MikeyC:

Q: When marking up forms, which is more semantically correct when separating form items?

  1. <form>
    <p><label for="name">Name:</label>
    <input type="text" id="name" /></p>
  2. <form>
    <label for="name">Name:</label>
    <input type="text" id="name" />
  3. <form>
    <label for="name">Name:</label>
    <input type="text" id="name" /><br /><br />

See all previous quiz questions and wrap-ups.