Why I Don’t Like Lists in Nav Elements

Last week in the Sparkbox office, the question came up whether or not it is necessary to use lists inside the HTML5 nav element.

Last week in the Sparkbox office, the question came up whether or not it is necessary to use lists inside the HTML5 <nav> element. I say no, it's not. Here's why.

Let's start off by looking back to before HTML5 existed. When structuring the markup for the main navigation, it might look something like this:

  
	<div class="main-nav">
		<ul>
			<li><a href="link-one.html" title="Link One">Link One</a></li>
			<li><a href="link-two.html" title="Link Two">Link Two</a></li>
			<li><a href="link-three.html" title="Link Three">Link Three</a></li>
			<li><a href="link-four.html" title="Link Four">Link Four</a></li>
		</ul>
	</div>
  

Fair enough. I think we all pretty much have agreed that is the standard. So when HTML5 came along and added the <nav> element, naturally markup started looking like this:

  
	<nav>
		<ul>
			<li><a href="link-one.html" title="Link One">Link One</a></li>
			<li><a href="link-two.html" title="Link Two">Link Two</a></li>
			<li><a href="link-three.html" title="Link Three">Link Three</a></li>
			<li><a href="link-four.html" title="Link Four">Link Four</a></li>
		</ul>
	</nav>
  

That, in itself, is not wrong. And certainly there is a case for that (for example, nested navigation). But, it's not necessary.

To make my point a little clearer, first let's look at the actual definition of the <nav> element.

The <nav> element represents a section of a page that links to other pages or to parts within the page: a section with navigation links. Not all groups of links on a page need to be in a <nav> element only sections that consist of major navigation blocks are appropriate for the <nav> element. In particular, it is common for footers to have a list of links to various key parts of a site, but the footer element is more appropriate in such cases, and no <nav> element is necessary for those links.

The HTML 5 specification

In the past, <ul> was used to "contain" a list of navigation links. Now the <nav> element exists and, by definition, groups the links. So the <ul> is unnecessary.

  
	<nav>
		<a href="link-one.html" title="Link One">Link One</a>
		<a href="link-two.html" title="Link Two">Link Two</a>
		<a href="link-three.html" title="Link Three">Link Three</a>
		<a href="link-four.html" title="Link Four">Link Four</a>
	</nav>
  

So Basically...

Is an unordered list necessary? No. Can it be used? Absolutely. Should it be used by default just because that's how you've always done it? Definitely not.

Disagree?

Read Rob Tarr's thoughts on the same subject and realize I make more sense.