Lists
ul, ol, li, dl — organise your content
Skills taught: html.lists, html.ul, html.ol, html.dl
HTML has three list elements, each for a different purpose:
- **ul** (unordered list) — bullets, for items with no required order
- **ol** (ordered list) — numbers, for steps or ranked items
- **dl** (description list) — term/definition pairs, for glossaries or metadata
<ul>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>
<ol>
<li>Open your code editor</li>
<li>Create an index.html file</li>
<li>Add your HTML boilerplate</li>
<li>Open in a browser</li>
</ol>
Tip:
<dl>
<dt>HTML</dt>
<dd>HyperText Markup Language — the structure of web pages</dd>
<dt>CSS</dt>
<dd>Cascading Style Sheets — the visual presentation of web pages</dd>
<dt>JavaScript</dt>
<dd>A programming language that makes web pages interactive</dd>
</dl>
Lists can be **nested** — place a new ul or ol inside an li to create sub-lists.
<ul>
<li>Front-end
<ul>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>
</li>
<li>Back-end
<ul>
<li>Node.js</li>
<li>Python</li>
</ul>
</li>
</ul>
Frequently Asked Questions
Can I put a p inside an li?
Yes. li can contain block-level content including p, blockquote, and even nested lists. This is common for complex list items.
How do I remove the default bullets with CSS?
Use list-style: none on the ul or ol. Also add padding: 0 and margin: 0 since browsers add default spacing.
When should I use dl vs a table?
Use dl for pairs of terms and their descriptions (glossaries, metadata). Use a table when you have multiple properties per item across rows and columns.