when to use UL or OL in html?

HtmlSemantics

Html Problem Overview


Seems interchangable?

Html Solutions


Solution 1 - Html

UL means "unordered list". OL means "ordered list".

UL gets you bullet points. OL gets you numbers.

Definitely not interchangable.

Solution 2 - Html

In math terms (hey, why not?), an <ol> represents a sequence, whereas <ul> represents a set. Rearranging the items in an ordered list changes the list's meaning. Rearranging them in an unordered list does not.

This is a good rule-of-thumb for which type of list to use. If changing the order of the items makes the list incorrect, you want to use <ol>. If the order doesn't matter, use <ul>.

Solution 3 - Html

With <ol> the order of the data is important and will be displayed (by default) while with <ul>, order isn't as important. Example:

<p>Tomorrow I will</p>
<ol>
 <li>Wake up</li>
 <li>Have breakfast</li>
 <li>Go to sleep</li>
</ol>
<p>During breakfast, I will eat</p>
<ul>
 <li>Butter</li>
 <li>Eggs</li>
 <li>Bacon</li>
</ul>

Solution 4 - Html

One is ordered list (OL), it is for things that have a defined and distinct order. There is a reason behind why they are organized.

The other (UL) is unordered list, which is just a collection of things in no specified order. Their organization is trivial.

Solution 5 - Html

Haha, so many answers!

When HTML first came out, there were OL and UL, which, as all of the other posters have said, meant Ordered List and Unordered List.

The difference was easy. OLs displayed... a number next to them. Or a roman numeral, or a letter! You could even control whether it used capitalized symbols or lowercase! Cool!

ULs gave you bullets. 3 types of bullets, even - discs (hollow circles), squares (filled squares), circles (filled circles.)

There was no CSS. Beyond these attributes, there wasn't really a way to customize the list formats (and margins and indententations and everything else.) So, this distinction was important.

Nowadays, its all CSS. In fact, the w3 people want you to use styles rather than the html "type" attribute that you used to use. So, using UL vs OL doesn't really matter, if you are one of them newfangled CSS users.

CSS lets you change the bullet type, or opt to use an image, or change the margins/styles/indentations, or not even display a bullet at all.

Edit again: This answer isn't really meant to address the semantic merits of UL vs OL. But technically (you know, at the bits and bytes) the above outlines the differences in behavior.

Solution 6 - Html

OL:

  1. List item 1
  2. List item 2

UL:

  • List item 1
  • List item 2

OL is ordered list, UL is unordered list

Solution 7 - Html

As the question asks "when to use them", I thought appropriate to offer examples of when, I usually decide to use OL when I want a series of steps, and UL when I want to offer choices:

Ordered list

Here the steps are critical for the business case, we must do the steps in this order, therefore an ordered list is used.

Checkout stages on eCommerce, these steps will be in this order.

<ol>
    <li>shipping</li>
    <li>billing</li>
    <li>summary</li>
    <li>confirmation</li>
</ol>

Unordered list

A user may decide on the order they choose to interact with these choices

<ul>
    <li>Contact Us</li>
    <li>Newsletter Signup</li>
    <li>Terms</li>
    <li>Log out</li>
</ul>

Solution 8 - Html

I think it's a sematic issue, as the numbering/bullet points can be changed by CSS.

Ordered lists should be things like instructions, or any sequential information.

Unordered lists should be everything else.

Solution 9 - Html

Use OL when you're listing steps that need to be done in a certain order. Use UL when you're listing items in no particular order of importance.

Solution 10 - Html

ul means unorded list. It is for lists in whick it doesn't matter what order the list items are in.

ol means ordered list. It is for lists that are numbered or in some way show that they have a specific ordering.

By default ul gets you bullet pointed lists and ol numbered lists, although this can be edited in css.

Solution 11 - Html

In some cases (specifically used by Screen Readers for people with special needs) you may want to have ordered list but not have numbers associated with them due to visual design. Ex. when you've let's say instructions on a page to fill up a form and want screen readers to take advantage of ordered items in the instructions then it will be useful. For all visual purposes they can be made to look exactly the same through CSS. It's the (non-visual, but helpful to screen reader) semantics that are different and at times useful.

Solution 12 - Html

ol = means ordered list. Use when you want to list and number things. ul = means unordered list. Use when you want to list but not number them.

I think OL should have been called NL = numbered list. Why? Because UL can also have an order but not be numbered.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionomgView Question on Stackoverflow
Solution 1 - HtmlRandolphoView Answer on Stackoverflow
Solution 2 - HtmlBen BlankView Answer on Stackoverflow
Solution 3 - HtmlbasaundiView Answer on Stackoverflow
Solution 4 - HtmlIan ElliottView Answer on Stackoverflow
Solution 5 - HtmlpoundifdefView Answer on Stackoverflow
Solution 6 - HtmlZachView Answer on Stackoverflow
Solution 7 - HtmlNeilView Answer on Stackoverflow
Solution 8 - HtmlMatthew GrovesView Answer on Stackoverflow
Solution 9 - HtmljoebertView Answer on Stackoverflow
Solution 10 - HtmlAndrew MarshView Answer on Stackoverflow
Solution 11 - HtmlkaroraView Answer on Stackoverflow
Solution 12 - HtmlkintsukuroiView Answer on Stackoverflow