Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why webmasters use `ul/li` instead of `div`s for layout?

As far as I know ul / li are typography specific tags, intended to format text as a list (while search engines love semantic tags).

My big question here is why Web Masters prefer to use lists solution (ul/li) where is an obvious case of a layout (div) solution, preferring to modify a lot of style for list semantic tags making it look like a div solution?

Are they just mistakes of use or I'm missing important facts here?

I'm asking this because, in many cases this is valid for a lot of widget plug-ins out in wild, which generate the html code dynamically (via JavaScript), even though some search engines don't support (or have limited support of) JavaScript. ex : FlipClockJs, Bootstap Components (carousel, nav, pagination), etc.

like image 779
Tiberiu C. Avatar asked Mar 11 '15 16:03

Tiberiu C.


People also ask

Should I use div or li?

<li> means an item in a list and that lets parsers (browsers, search engines, spiders) know that you're listing items. You can use DIV instead of LI but those parsers would never know that those items are being listed and DIV does not really describe anything except that it's a block. Save this answer.

What is UL and Li in CSS?

ul stands for unordered list. li stands for list item. They are the HTML tags for "bulleted" lists as opposed to "numbered" lists (which are specified by ol for ordered list).

Why should we use divs if they don't change things visually?

div (short for division) allows us to divide our page into different sections, to position this sections. Divs are very useful. The change might not be the most visual one, doesn't make it less useful. if we only used text, everything would just be from top to bottom.

What does UL and Li mean in HTML?

Unordered lists ( UL ), ordered lists ( OL ), and list items ( LI )


3 Answers

ul/ol/li are not typographic tags, they're semantic tags (tags that have a meaning). Lists are commonly used for lists of navigation links and similar because:

  1. Conceptually — indeed, semantically — a navigation menu is a list of places you might want to go, after all; and

  2. The unstyled version is easily understood (as a list)

E.g., styled:

ul {
  display: inline-block;
}
li {
  display: inline-block;
  border: 1px solid black;
}
li > a {
  display: block;
  cursor: pointer;
  text-decoration: none;
  padding: 1px;
}
li > a:hover {
  background-color: #eee;
}
<ul>
  <li><a href="#this">This</a></li>
  <li><a href="#that">That</a></li>
  <li><a href="#the-other">The other</a></li>
</ul>

Unstyled:

<ul>
  <li><a href="#this">This</a></li>
  <li><a href="#that">That</a></li>
  <li><a href="#the-other">The other</a></li>
</ul>
like image 179
T.J. Crowder Avatar answered Oct 03 '22 01:10

T.J. Crowder


As far as I know ul / li is are typography specific tags, intended to format text as a list (while search engines love semantic tags).

They are not. They are semantic elements that say the content is a set of list items where the order is not of particular importance.

My big question here is why Web Masters prefer to use lists solution (ul/li) where is an obvious case of a layout (div) solution

Divs are not related to layout. Layout is the job of CSS. The elements used should be selected based on the semantics they convey, then CSS should be applied to them to give the desired rendering.

A div element is an element of last resort. It has no semantics and should be used when HTML doesn't have an element with appropriate semantics for the content.

like image 45
Quentin Avatar answered Oct 03 '22 02:10

Quentin


I had never given any thought to the idea of lists being typographic specific before but this question made me wonder if lists were inappropriate for layout. The HTML5 spec doesn't say anything that I could immediately find to agree with that but one aside is in the li specification:

While it is conforming to include heading elements (e.g. h1) inside li elements, it likely does not convey the semantics that the author intended. A heading starts a new section, so a heading in a list implicitly splits the list into spanning multiple sections.

This gives rise to questioning whether lists are appropriate for all layout situations. If you are using lists to show a group of products, and those products are written using sectioning elements, does that put them under the problem called out by the quote above?

like image 32
Rob Avatar answered Oct 03 '22 01:10

Rob