131

I'm not sure why I need to use ul-li vs simply using divs when listing items. I can make both look exactly the same so where is the functional advantage to creating an unordered list vs lining up divs?

Ambo100
  • 1,185
  • 3
  • 15
  • 28
zsharp
  • 13,656
  • 29
  • 86
  • 152
  • 2
    Brilliant question. I have been searching for this for a while. I hope there is some reasonable answer below. – runios Dec 02 '17 at 08:35

15 Answers15

160

For semantic correctness. HTML has the ability to express lists of things, and it helps the Google robot, screen readers, and all manner of users who don't care solely about the presentation of the site understand your content better.

Jeremy DeGroot
  • 4,496
  • 2
  • 20
  • 21
  • 4
    +1. For the visually impaired, it can be helpful to distinguish what's in a list and what's not. Say if you have a list of ingredients in a recipe for example, and the user wants to skip to the instructions or just read the list, you need a list. – Dave Markle Feb 14 '09 at 19:57
  • +1. zsharp: You say so yourself, "when listing items". You list up things when adding them to a list. – Arve Systad Feb 14 '09 at 21:39
  • 3
    @Arve. My point was to get to the functional difference despite the name "list". Oteherwise I would be following rules i didnt understand. – zsharp Feb 15 '09 at 03:31
  • 3
    HOWEVER, back in the day (and maybe still), each browser added it's own little formatting to list elements, like spacing, margins, etc, so that is exactly why a lot of people prefer using divs. because no one wants to add a bunch of code to zero out formatting, or to detect browsers, and those slight differences would often break page layouts, doing ugly things like putting white lines between image "slices" and bumping items down below others. – AwokeKnowing May 27 '15 at 22:00
  • @AwokeKnowing Actually, CSS reset projects are Legion precicely because professional front-end devs _do_ want to add a bunch of code to zero out formatting. They "reset" default styles of all the browsers to a known, "styleless", base. – joshperry Aug 17 '15 at 16:11
  • @joshperry sure, I agree that many, possibly most go that route. But there is a growing school of though that uses HTML to just define and label the object graph (tree structure with class names), and actually use CSS classes for ALL the style. Having some html elements have some bits of arbitrary style is not good separation of concerns. You can argue that resets solve that, but many prefer to have all their style expressed in css classes, eg
    instead of splitting it half between the element type and class,
  • .
– AwokeKnowing Aug 17 '15 at 21:49
  • @AwokeKnowing Agreed, and I think we are mostly saying the same thing. For e.g. see: http://meyerweb.com/eric/tools/css/reset/ This is a very popular, and simple, CSS reset that clears all padding, margins, borders, and list styles to zero/none. – joshperry Aug 17 '15 at 22:06
  • @AwokeKnowing - Also worth knowing about here is Normalize (https://necolas.github.io/normalize.css/) – Isaac Gregson Aug 31 '16 at 13:08
  • You mentioned Google. Funny enough, their code oftentimes is trash that violates both the semantic principle you correctly talk about and even such basic concepts that IDs ("#") in HTML are supposed to be unique. – DDRRSS Jan 28 '22 at 05:33