A shopping memo, a set of steps, a list of favorites. Moments where “several things line up” come up surprisingly often, don’t they? That’s when you reach for a list. It reads far more easily than cramming everything into one long paragraph.
Start with a bulleted list
For a list with no particular order, line up <li> items inside a <ul>.
<ul>
<li>Red bean bun</li>
<li>Milk</li>
<li>Apple</li>
</ul>| Tag | Meaning |
|---|---|
<ul> | Short for “unordered list” (a list with no order). The outer box |
<li> | Short for “list item.” The individual things lined up inside |
You put several <li> items inside the <ul> box. “Nesting” makes an early appearance here. When displayed, each item gets a ”•“-like dot in front.
When you want numbers
When the order matters, like “step 1, 2, 3,” just change <ul> to <ol>.
<ol>
<li>Boil the water</li>
<li>Add the powder</li>
<li>Wait 3 minutes</li>
</ol><ol> is an ordered list (a list with an order). The <li> items inside stay the same. Then, instead of dots, you get numbers: 1. 2. 3. You don’t have to write the numbers yourself — the browser adds them in order for you.
<ul> (bullets), the bottom is <ol> (numbers). The contents are written exactly the same way; only the mark in front changes.A list inside a list (nesting)
When you want to hang finer items under “Fruit,” you put a whole other list inside the <li>.
<ul>
<li>Fruit
<ul>
<li>Apple</li>
<li>Orange</li>
</ul>
</li>
<li>Vegetables</li>
</ul>This way, “Apple” and “Orange” appear indented one step under “Fruit,” and the parent-child relationship comes across visually too. Perfect for a table of contents or sorting into categories.
An li’s contents aren’t limited to short words
The examples so far have put only short words in <li>, but since <li> is a box, it can hold a longer explanation too.
<ul>
<li>
<p>Breakfast</p>
<p>Get bread and eggs ready</p>
</li>
<li>
<p>Lunch</p>
<p>Shape some rice balls</p>
</li>
</ul>Here we put a title and a description together into a single <li>. As long as it’s “the contents of one item,” <li> doesn’t mind how many <p> you put inside.
<p> inside, you can see the list still treats it as a single item.Summary of this lesson
- Wrap a list in
<ul>(or<ol>), and write the items with<li> - Bullets are
<ul>, numbers are<ol> - Always put
<li>inside a list
