Question

Are there any technical reasons (CSS / jQuery related) why to use <ul> tag for navigation bars, instead of just using a tags?

<nav>
  <ul class="links">
    <li><a href="/">Home page</a></li>
    <li><a href="/about">About page</a></li>
  </ul>
</nav>

vs

<nav>
    <a href="/">Home page</a>
    <a href="/about">About page</a>
</nav>
Was it helpful?

Solution

  • It's, arguably, 'more semantic': those links probably are a list
  • Without the nav element, (i.e. in HTML5), the ul often provides a useful container for styling

OTHER TIPS

Unlike XML, you cannot make-up tags in HTML. Sure, will probably work but it's invalid mark-up.

Lists usually provide a nice way to mark things up that make sense. Structure, it usually makes sense (you typically have a list of items in your navigation, no?). Definition lists can lend themselves to some forms of navigation but lists usually make the most sense.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top