0

Do I have to use ul/ol elements when I make navbars/other groups of links or it is optional?

Is it ok to replace this code

<div>
  <ul style="list-style: none">
    <li style="display: inline-block"><a href="#">fb page</a></li>
    <li style="display: inline-block"><a href="#">twitter account</a></li>
    <li style="display: inline-block"><a href="#">stackoverflow account</a></li>
  </ul>
</div>

by

<div>
    <a href="#" style="display: inline-block">fb page</a>
    <a href="#" style="display: inline-block">twitter account</a>
    <a href="#" style="display: inline-block">stackoverflow account</a>
</div>

?

4 Answers4

1

The answer lies in using the correct semantics. The navigation is a list of links, thus we treat it as a list. <ul> and <ol> stand for unordered and ordered lists respectively. The <div> tag has almost no semantic meaning.

nicholaschris
  • 1,401
  • 20
  • 27
1

Structurally and theoretically speaking speaking, a menu is a list of links, so your markup should reflect it as a list of links. You can style it to make the effects of the list invisible in graphical browsers.

Practically speaking, structure is useful. Look at what happens if you don't have the list and you view the page without a stylesheet. Can you tell where one link ends and the next begins?

screenshot of lynx

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

It doesn't matter: you can use either <ul> or <div> but the actual symbol in <li> shall not be visible in menu. Rgds,

Alexander Bell
  • 7,842
  • 3
  • 26
  • 42
0

Short answer: No, you don't have to use them.

Long answer: The list tags (<ul>, <ol>) are traditionally used for the purpose of creating navigable menus and there are many available stylesheets that will correctly style them as menus, drop downs, etc. That said, this is only a common (though useful) convention. You don't have to follow the convention, but you will make your life (and more importantly, the life of any developer who comes after you) easier if you do.

Peter Gluck
  • 8,168
  • 1
  • 38
  • 37