HTML Unordered Lists
Packing for a trip, you might write: passport, charger, umbrella, sunglasses. It does not matter which one you pack first. They are just a group of things that belong together.
In HTML, that kind of group is an unordered list. It is the list you will use most often: for features, ingredients, tags, links, requirements, and many other collections. In this lesson, you will learn how it works, what you can put inside it, and how to use it well.
What You Will Learnβ
- What an unordered list is, and when to use it
- How
<ul>and<li>work together - What can (and cannot) go inside a list
- What a list looks like by default
- Real-world patterns: features, links, and menus
- Common mistakes, and how to avoid them
The Basics: <ul> and <li>β
An unordered list needs two elements:
| Element | Name | Job |
|---|---|---|
<ul> | Unordered List | The container for the whole list |
<li> | List Item | One item inside the list |
- HTML Code
- Browser Output
<h3>Pack for the trip</h3>
<ul>
<li>Passport</li>
<li>Phone charger</li>
<li>Umbrella</li>
<li>Sunglasses</li>
</ul>
Pack for the trip
- Passport
- Phone charger
- Umbrella
- Sunglasses
Each <li> becomes a new line with a bullet marker. You do not type the bullets yourself. The browser adds them.
It means the order does not change the meaning. Swap "Passport" and "Umbrella," and the list says the same thing. If order does matter, you need an ordered list.
Default Appearanceβ
Out of the box, browsers style an unordered list like this:
- Each item starts on a new line.
- Each item gets a solid round bullet (called a disc).
- The list is indented on the left, usually about 40 pixels, to make room for the bullets.
- The list has some space above and below it.
This is only the default. With CSS, you can change the bullets, remove them, or lay the items out in a row. You will learn that in Styling Lists. For now, here is a quick preview.
- HTML Code
- Browser Output
<ul style="list-style-type: square;">
<li>Square markers</li>
<li>Still the same list</li>
</ul>
<ul style="list-style-type: none;">
<li>No markers at all</li>
<li>Still the same list</li>
</ul>
- Square markers
- Still the same list
- No markers at all
- Still the same list
Older HTML used a type attribute on <ul> to pick bullet shapes. That is now obsolete. Use the CSS property list-style-type instead.
What Can Go Inside an <li>?β
A list item can hold almost anything: plain text, links, images, bold text, even paragraphs and other lists.
- HTML Code
- Browser Output
<ul>
<li>Plain text</li>
<li>A <a href="#">link</a> inside text</li>
<li><strong>Bold text</strong> and <em>emphasis</em></li>
<li>
A longer item with two paragraphs.
<p>The second paragraph stays inside the same item.</p>
</li>
</ul>
- Plain text
- A link inside text
- Bold text and emphasis
A longer item with two paragraphs.
The second paragraph stays inside the same item.
What Can Go Directly Inside <ul>?β
This is the part beginners often get wrong. The only elements allowed as direct children of <ul> are <li> elements. (Script-supporting elements like <script> and <template> are also allowed, but you will rarely need them here.)
- Invalid
- Valid
<ul>
<h4>My list</h4> <!-- heading inside ul -->
<li>One</li>
<p>Two</p> <!-- paragraph inside ul -->
Three <!-- loose text -->
</ul>
<h4>My list</h4> <!-- heading goes before the list -->
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
Browsers will usually show invalid lists anyway, which is why the mistake goes unnoticed. But screen readers and tools can get confused. Keep the structure clean.
When to Use an Unordered Listβ
Use <ul> when you have a group of related items where the order does not matter.
| Good use | Example |
|---|---|
| Features of a product | Fast, Secure, Free |
| Ingredients | Flour, sugar, eggs |
| Requirements | Laptop, internet, a text editor |
| Tags or categories | HTML, CSS, JavaScript |
| A set of links | Menu items, related articles |
| Pros and cons | Each side as its own list |
Not a Good Useβ
- Steps that must happen in order: use
<ol>. - Terms with definitions: use
<dl>. - A single sentence or idea: use a paragraph. A list with one item is rarely useful.
- Layout only: if you want items side by side and nothing is really a list, use CSS layout on
<div>elements instead.
Real-World Examplesβ
1. A Feature Listβ
- HTML Code
- Browser Output
<h3>Why learn HTML?</h3>
<ul>
<li><strong>Every site uses it.</strong> It is the base of the web.</li>
<li><strong>Easy to start.</strong> You need only a text editor.</li>
<li><strong>Free.</strong> No cost to learn or to publish.</li>
</ul>
Why learn HTML?
- Every site uses it. It is the base of the web.
- Easy to start. You need only a text editor.
- Free. No cost to learn or to publish.
2. A List of Linksβ
Menus and "related articles" are really lists of links.
- HTML Code
- Browser Output
<h3>Related lessons</h3>
<ul>
<li><a href="/html/text-content/headings">Headings</a></li>
<li><a href="/html/links-and-navigation/anchor-element">The anchor element</a></li>
<li><a href="/html/images">Images</a></li>
</ul>
Related lessons
In the live demo, the links use # so that nothing navigates away. In your project, they point to real pages.
3. A Navigation Menuβ
Placing a list inside <nav> marks it as site navigation. With a little CSS, it becomes a horizontal menu. You built one in Navigation Menus.
<nav aria-label="Main">
<ul>
<li><a href="/">Home</a></li>
<li><a href="/courses">Courses</a></li>
<li><a href="/about">About</a></li>
</ul>
</nav>
4. Pros and Consβ
When you compare two things, give each side its own list under a clear heading.
- HTML Code
- Browser Output
<h4>Pros</h4>
<ul>
<li>Quick to learn</li>
<li>Works in every browser</li>
</ul>
<h4>Cons</h4>
<ul>
<li>Needs CSS for styling</li>
<li>Needs JavaScript for behavior</li>
</ul>
Pros
- Quick to learn
- Works in every browser
Cons
- Needs CSS for styling
- Needs JavaScript for behavior
Writing Good List Itemsβ
A list is only as useful as its items. These habits make lists easier to scan, and easier to translate.
- Keep items short. Aim for a phrase or one sentence. If an item needs a full paragraph, ask whether a list is the right tool.
- Make items parallel. Start each one the same way. "Install Node," "Create a folder," "Run the server" reads better than a mix of styles.
- Be consistent with punctuation. Use a period after every item if they are full sentences, or none if they are short phrases. Do not mix.
- Put the key word first. People scan the start of each line.
- Introduce the list. A heading or sentence before it ("You will need:") gives context.
- Do not nest too deep. One or two levels is plenty. More makes a list hard to follow.
- Messy
- Clean
<ul>
<li>you should install node.</li>
<li>Creating a folder</li>
<li>The server must be run</li>
</ul>
<ul>
<li>Install Node.</li>
<li>Create a folder.</li>
<li>Run the server.</li>
</ul>
The <menu> Element: A Close Cousinβ
You may also meet a <menu> element. In modern HTML it is a semantic alternative to <ul> for toolbars and sets of commands (such as Bold, Italic, Underline buttons). It behaves like <ul> and contains <li> items.
<menu>
<li><button type="button">Bold</button></li>
<li><button type="button">Italic</button></li>
</menu>
For ordinary bullet lists and navigation, stick with <ul>. It is the choice everyone expects, and the one with the best tool support.
Accessibility at a Glanceβ
Screen readers announce a real <ul> as "list, 4 items," and let users jump between items. This is one more reason to use true lists.
- Do not fake lists with
<br />and dashes. Assistive technology will not announce them as lists. - Be careful with
list-style: none. In some browsers, removing the bullets can also remove the list semantics from screen readers. If you hide the bullets on a list that is still a list, addrole="list"to<ul>. You will see why in Accessible Lists.
Common Mistakes to Avoidβ
- Putting text, headings, or
<p>directly inside<ul>. Only<li>is allowed there. - Forgetting to close
<li>or<ul>. Missing tags can break the layout of everything after the list. - Using
<ul>for ordered steps. If someone must follow the sequence, use<ol>. - Using a list for a single item. One bullet is just a sentence.
- Faking bullets with characters like
β’,-, or*inside paragraphs. - Using
<ul>only for indentation. Use CSS margin or padding for spacing. - Using the obsolete
typeattribute. Choose bullet shapes with CSSlist-style-type. - Mixed, inconsistent items. Keep wording and punctuation parallel.
Practice Timeβ
Open your editor and try these:
- Write a bullet list of five things you want to learn this year.
- Add a heading above the list that introduces it.
- Turn one item into a link, and make another one bold.
- Make a list of three of your favorite websites as links.
- Wrap a list of links in
<nav>to make a simple menu. - Write "Pros" and "Cons" lists for a tool you use.
- Change the bullets to squares, then remove them, using
list-style-type. - Rewrite a messy list so that all items start the same way.
- Bonus: add a second paragraph inside one
<li>.
Quick Recapβ
Click a question to check your answer.
1. Which two elements make an unordered list?
<ul> is the list container, and each entry inside it is an <li>.
2. When should you choose <ul> instead of <ol>?
When the order of the items does not change their meaning, such as ingredients, features, or links.
3. What are the only elements allowed directly inside <ul>?
<li> elements. Headings, paragraphs, and loose text must go inside an <li> or outside the list.
4. How do you change the bullet shape?
With the CSS property list-style-type, for example square or none. The old type attribute is obsolete.
5. Why is a real list better than dashes and <br />?
Screen readers, search engines, and CSS all understand a real list, but they cannot tell that a fake one is a list.
Key Takeawaysβ
- An unordered list is a
<ul>with<li>items, for groups where order does not matter. - Only
<li>elements belong directly inside<ul>. An<li>itself can hold text, links, images, and more. - Browsers add bullets and indentation by default. Change them with CSS, not with HTML attributes.
- Menus, link groups, and feature lists are all unordered lists in disguise.
- Write short, parallel items, introduce the list, and always use a real list instead of faking one.
Your lists can now hold a group of things. But what about steps that must happen in a certain sequence? Move on to Ordered Lists, or go back to the Lists overview.