On this page11 sections
Lecture 013: Styling Lists
| Category | 3: Text, Fonts & Content |
| Lecture | 013 of 057 |
| Estimated video length | 8 min |
| Target | CSS3 · any modern browser |
| Level | Beginner |
Bullets and numbers don't have to be plain black dots. CSS can change the marker, use an image or emoji, move it inside the text, remove it completely for menus, and colour each item.
Learning Objectives
- Change markers with
list-style-typeandlist-style-image - Move markers with
list-style-position - Remove default list styling for menus
- Colour and space list items, and style the
::marker
1. Marker Types
Example
<style>
ul, ol { margin-bottom: 10px; }
</style>
<ul style="list-style-type: circle;"><li>circle</li><li>circle</li></ul>
<ul style="list-style-type: square;"><li>square</li><li>square</li></ul>
<ol style="list-style-type: upper-roman;"><li>upper-roman</li><li>upper-roman</li></ol>
<ol style="list-style-type: lower-alpha;"><li>lower-alpha</li><li>lower-alpha</li></ol>
<ul style="list-style-type: '✅ ';"><li>A custom string</li><li>Any text works</li></ul>2. An Image as the Marker
ul { list-style-image: url('tick.png'); }For more control over size and position, many developers use a ::before with a background image instead (Lecture 020).
3. Marker Position
Example
<style>
li { background: #e7f5ff; margin: 4px 0; }
</style>
<ul style="list-style-position: outside;"><li>outside (default): the bullet hangs in the margin, and wrapped lines line up with the text</li></ul>
<ul style="list-style-position: inside;"><li>inside: the bullet sits inside the box, and wrapped lines go under it</li></ul>4. Removing Default Styles (for Menus)
Example
<style>
ul.plain { list-style: none; margin: 0; padding: 0; }
ul.plain li { padding: 8px; border-bottom: 1px solid #dee2e6; }
</style>
<ul class="plain">
<li>Dashboard</li>
<li>Messages</li>
<li>Settings</li>
</ul>list-style: none removes the markers, and padding: 0 removes the left indent. Navigation bars start like this (Lecture 021).
5. Colours and the ::marker
Example
<style>
ol.steps li::marker { color: #e8590c; font-weight: bold; }
ul.zebra { list-style: none; padding: 0; }
ul.zebra li { padding: 8px 12px; }
ul.zebra li:nth-child(odd) { background: #f1f3f5; }
</style>
<ol class="steps">
<li>Mix flour and water</li>
<li>Knead for 10 minutes</li>
<li>Rest for an hour</li>
</ol>
<ul class="zebra">
<li>Apples</li><li>Bananas</li><li>Cherries</li><li>Dates</li>
</ul>6. The Shorthand
ul { list-style: square inside; }
/* list-style: type position image; */Common Beginner Mistakes
1. Removing markers but not padding. The list still has a gap on the left.
2. Styling the <ul> colour to colour bullets. That colours the text too. Use ::marker.
3. Typing bullets into the HTML. <li>• Apples</li> doubles up. Let CSS add markers.
Practice Questions
- Make a bullet list use squares.
- Number an ordered list with Roman numerals.
- Remove all list styling for a menu.
- What does
list-style-position: insidedo? - Colour only the numbers of an ordered list red.
Practice Answers
ul { list-style-type: square; }ol { list-style-type: upper-roman; }(orlower-roman)ul { list-style: none; margin: 0; padding: 0; }- It moves the marker inside the list item's box, so wrapped lines go under it.
ol li::marker { color: red; }
Key Takeaways
list-style-typechanges the marker; it can even be a string such as'✅ '.list-style-positiondecides whether markers sit inside or outside.list-style: none; padding: 0;is the starting point for menus.::markerstyles bullets and numbers on their own.