Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are web developers so keen to use lists?

Tags:

html

css

I've been developing for a while and often develop sites using menu tabs.

And I can't figure out why so many web developers like using lists < ul >< li > etc rather than just using plain old divs.

I can make menus in divs which are simple and work perfectly in every browser. With lists, I'm usually trying to hack it one way or another to get it work properly.

So my question is simple : why should I use lists to create my menus instead of divs ?

like image 587
Bob Avatar asked Apr 20 '10 10:04

Bob


2 Answers

Simple: Semantic HTML. Navigation is essentially a list of links in your HTML, so your markup should reflect this.

It has several benefits, search engine spiders can intelligently figure out what is a list of stuff (ie. your nav) and google specifically does clever things with it.

Also, users with text only browsers or screen readers can instantly recognise navigational elements with ease.

Besides, it's good practice.

like image 152
dangvy Avatar answered Oct 23 '22 06:10

dangvy


If you take your menu as an example, then menus by nature can be hierarchical, and an HTML list is specifically designed for marking-up a hierarchical list of items. It is the semantically correct mark-up for that type of item and will be easily understood by any type of user-agent whether CSS is enabled or not (think of screen readers, web robots etc.)

There absolutely no reason you should find it harder to style a nested list as a sequence of 'flat' divs. In fact, quite the contrary, since you CSS syntax is designed to easily differentiate nested items.

like image 34
Dan Diplo Avatar answered Oct 23 '22 06:10

Dan Diplo