How to Create Simple and Effective Sub Navs with Definition Lists by Mark
October 12, 2009 in Implementation with 7 Comments
We use our extranet daily to present a lot of work to our clients. From wireframes to Photoshop mockups and business goals to sketched opportunities, we have several established ways of presenting information. One of the ways we handle versioning, or the updating of assets on the extranet, is through a dl-powered navigation list.
When we need simple and effective on-page navigation, to either jump to content on the page or flip to another view, we use the dl element. Its sub elements, the dt and dd, make it very easy for us to create inline links with a clear label. Here we're going to share with you a fast, lightweight method for how we'll use CSS to do it.
What's a DL?
The dl element is a definition list. Plain and simple, it's an HTML element that is used to display terms (dt) and their descriptions (dd). However, definition lists aren't just semantically limited to dictionary style definitions. Rather, they are very versatile and can be used in a handful of meaningful ways:
- Showing terms and descriptions (like a dictionary)
- Presenting dialogue between people
- Showing simple biographical information for a person
Each instance is still semantically correct (you have a term and description), but serves a variety of different uses. We love to see HTML elements be flexible enough for varied applications and have no problem utilizing them this way in our own work.
Creating the Sub Navigation
As we mentioned before, we use dls for simple, scalable sub navigations. It's an easy and semantically correct way of labeling a set of links for added context. To better illustrate what we mean, here's a screenshot from one of our client's extranet page:
As shown above, the light gray "label" is the dt while the sub links are instances of dds with links inside. The gray label on the left helps tell users what this nav is for: links on this page. This makes our nav easy to understand and more meaningful. Now, let's break down the HTML and CSS used to create this sub navigation.
The HTML
We'll use four HTML elements to create the necessary markup for our sub navigation. Take a look:
<dl class="nav"><dt>On this Page:</dt><dd class="active"><a href="#">Final Wireframes</a></dd><dd><a href="#">Updated Wireframes</a></dd><dd><a href="#">Initial Wireframes</a></dd><dd><a href="#">Sketches</a></dd></dl>
The CSS
The CSS is equally simple as the HTML. We've coded up styles for the entire list below, including an active or current state for our links. Check it out:
- dl.nav {
- width: auto;
- height: 27px;
- margin: 0 0 18px;
- }
- dl.nav dt, dl.nav dd {
- float: left;
- display: inline;
- }
- dl.nav dt {
- color: #999;
- font-weight: normal;
- }
- dl.nav dd a {
- margin-left: 6px;
- padding: 5px 12px;
- text-decoration: none;
- -webkit-border-radius: 12px;
- -moz-border-radius: 12px;
- }
- dl.nav a:hover {
- background: #eee;
- }
- dl.nav dd.active a {
- background: #2daebf;
- color: #fff;
- }
Here's a quick step-by-step look at what we're doing with the CSS for the list:
- First, we ensure the dl can properly contain all children elements, so we fix the width and height. (This is the best option for quick cross browser compatibility).
- Then we float: left; the links and list label to make them appear all on one line.
- Next we give our links and list label their own styling
- And finally we add our hover and active states for the links so users know which page they're on.
And that's that. Small HTML footprint and light, flexible CSS that works well across all browsers (save the browser extensions) and doesn't even require any images.
The Finished Demo
We've put together a shorter walk-through with our demo code. It works in all browsers, but it works especially well in Safari and Firefox (due to the rounded corners). Be sure to check it out and leave your questions or comments below!










7 Comments
Dwayne Anderson says:
Nice work, and very interesting... I've always thought of the definition list (dl) as one of the most under-utilized elements in HTML. But I've never personally used it outside of a scenario where there is not a 1:1 ratio of the definition terms (dt) to definition descriptions (dd) within the list. I'm curious as to why you propose this solution, rather than a heading followed by an unordered list (ul), since the items in your example are essentially a list of items on the page. I'm not saying you're wrong in taking the approach you have – I'm simply looking for more insight as to the thought process that let to the decision.
Mark (ZURB) says:
@Dwayne: Glad you asked! The point here was to create a solution that was low on CSS, self containing, and easily scalable. A heading and an unordered list would have done the trick, yes, but they are different elements—we wanted one element to do the trick.
The choice in elements might seem odd, but it's easier to work with and style than a div wrapping a heading and an unordered list. Plus, it's fun to try something new! :)
Kevin Holesh says:
I did find your choice of HTML elements odd at first, but hearing you explain it helped me understand the thought process and reasoning behind it. This is definitely a better way to do this type of navigation and I'll definitely keep this in the back of my head.
I'm all about axing unnecessary markup where possible!
David says:
When do we get to see what your extranet pages look like? I love seeing how people handle deliverables.
Mark (ZURB) says:
@Kevin: We hear ya! We try to make things easy on ourselves, and combined with an urge to try new things and experiment with CSS, we end up with some crazy ideas. This was a pretty grounded one from several people on the team.
Mark (ZURB) says:
@David: Hah! Maybe soon—since so much of our work is under NDA, it's hard to say for certain if we would show anything to the public. We're also working on a new extranet in the coming months. Perhaps until then we'll share more about how we present information there?
Martin Korych says:
Two great articles in a row, just came across the Polaroid-transformation! You guys rule, more I say, more! + Thank you.
Add your comment...