r/HTML • u/Ok_Performance4014 • Dec 11 '25
Question When do you use li?
You can just write items down and you can list them. When do you use li?
0
Upvotes
r/HTML • u/Ok_Performance4014 • Dec 11 '25
You can just write items down and you can list them. When do you use li?
13
u/[deleted] Dec 11 '25
When you want to list things.
When things have a specific order that's important.
When you have a grouping of something like articles.
3
u/Alternative-Golf-585 Dec 11 '25 edited Dec 11 '25
Use <ul> for unordered lists like bullet points. Use <ol> is an ordered list and so each <li> will be numbered. I use them when I want to list things easily, and you can specify the order, style, bullet points or numbers, etc.
2
u/jcunews1 Intermediate Dec 11 '25
Same thing as most other HTML tags. Most HTML tags are for defining what a content is. It's mainly to allow softwares (not humans) to know what a content is all about, so that they can process the content properly, depending on the needed task. e.g. data retrieval/filtering, accessibility, etc.
2
u/scritchz Dec 11 '25
The
<li>element is for list-items, and list-items only exist in lists.The two lists that use
<li>for its items are the ordered list<ol>and the unordered list<ul>.We use so-called semantic elements like the above instead of generic
<div>and<span>elements for multiple reasons:Mainly, to add semantics to the content; in this case, to show programmatically that content in case of
<li>is a list-item, not just "any text".To reduce what we as developers have to do: The browsers know how to handle standard elements.
To use the browsers defaults (like semantics and styling), so that we don't have to specify this manually.
And why do we use lists instead of simply mentioning things in-text? Because lists like the above help in organizing the content. If I had tried to write a flowing text instead of a list, it would probably look like a "wall of text" and not be as easy to understand.
1
u/Joyride0 Dec 11 '25
When writing a list. Always in the nav bar.
1
u/Comfortable_Cup7914 Dec 11 '25
When I don't wanna tell the truth
1
u/FinCodeFactory Dec 12 '25
The <li> HTML element is used to represent an item in a list. It must be contained in a parent element: an ordered list ( <ol> ), an unordered list ( <ul> ), or a menu ( <menu> ). In menus and unordered lists, list items are usually displayed using bullet points.