In this tutorial, weâll learn how to style lists with CSS!
Remember that in HTML, we have two list types:
Unordered lists <ul>
â list items are defined with bullet points:
- Coffee
- Tea
- Biscuits
Ordered lists <ol>
â list items are defined with numbers (or letters i. ii. iii.):
1- Coffee
2- Tea
3- Biscuits
And each item is given the <li>
tag, like so:
<ol>
<li>Coffee</li>
<li>Tea</li>
<li>Biscuits</li>
</ol>
We use lists all the time when building on the web! Itâs fair to say that most navigation menus are essentially HTML lists, which have been styled using CSS.
How to style lists with CSS
CSS has several properties that we can use for styling. We can set different list item markers, use images as markers, as well as add colors & background colors.
Letâs take a look at the syntax!
list-style-type
We use list-style-type
to set a marker for our list:
li {
list-style-type: square;
}
There are in fact a whole lot of possible values! Such as circle
, square
, decimal
, upper-roman
and none
. See all the list style types.
Itâs worth mentioning that if youâre setting the color of the list marker â itâll default to whatever the element color is.
Also, youâll often use the list-style-type:none
property to remove the markers completely!
list-style-position
With list-style-position
you can position the marker outside
(default) or inside
of the list content:
li {
list-style-position: outside;
}
li {
list-style-position: inside;
}
When using inside
with lists of text for example, each marker will be contained within the text box, thus indenting the first line of text for each list item.
list-style-image
list-style-image
can be used to place a custom image as a marker:
li {
list-style-image: url(goldstar.png);
}
The URL points to the location of the image.
Itâs good practice to also set a list-style-type
as a fallback, in case the image is unavailable.
list-style (Shorthand)
The list-style
shorthand property lets us specify our list-style-type
, list-style-position
& list-style-image
in one declaration.
For example:
ul {
list-style: square inside url("goldstar.png");
}
This would be equivalent to:
ul {
list-style-type: square;
list-style-position: inside;
list-style-image: url(goldstar.png);
}
When using this shorthand property, be mindful of the order: list-style-type
, then list-style-position
and lastly list-style-image
. If any of these properties are missing, theyâll revert to their default state.
Related Posts:
A little about me..
Hey, Iâm Tim! đ
Iâm a freelance business owner, web developer & author. I teach both new and experienced freelancers how to build a sustainable and successful freelancing business. Check out my Complete Guide to Freelancing if you'd like to find out more.
While you're here, you can browse through my blogs where I post freelancing tips, code tutorials, design inspiration, useful tools & resources, and much more! You can also join the newsletter, or find me on X.
Thanks for reading! đ