The CSS list properties allow you to:
- Set different list item markers for ordered lists
- Set different list item markers for unordered lists
- Set an image as the list item marker
List
In HTML, there are two types of lists:
- unordered lists - the list items are marked with bullets
- ordered lists - the list items are marked with numbers or letters
With CSS, lists can be styled further, and images can be used as the list item marker.
Different List Item Markers
The type of list item marker is specified with the list-style-type property:
Example
<html>
<head>
<style type="text/css">
ul.a {list-style-type:circle;}
ul.b {list-style-type:square;}
ol.c {list-style-type:upper-roman;}
ol.d {list-style-type:lower-alpha;}
</style>
</head>
<body>
<p>Example of unordered lists:</p>
<ul class="a">
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
<ul class="b">
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
<p>Example of ordered lists:</p>
<ol class="c">
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ol>
<ol class="d">
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ol>
</body>
</html>
Try it yourself in Notepad or Dreamweaver by coping and pasting the code above.
Result:
Example of unordered lists:
- Coffee
- Tea
- Coca Cola
- Coffee
- Tea
- Coca Cola
Example of ordered lists:
- Coffee
- Tea
- Coca Cola
- Coffee
- Tea
- Coca Cola
Some of the values are for unordered lists, and some for ordered lists.
An Image as The List Item Marker
To specify an image as the list item marker, use the list-style-image property:
Example
<html>
<head>
<style type="text/css">
ul
{
list-style-image:url('your_image.gif');
}
</style>
</head>
<body>
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
</body>
</html>
Try it yourself in Notepad or Dreamweaver by coping and pasting the code above.
Result:
The example above does not display equally in all browsers. IE and Opera will display the image-marker a little bit higher than Firefox, Chrome, and Safari.
- Coffee
- Tea
- Coca Cola
The example above does not display equally in all browsers. IE and Opera will display the image-marker a little bit higher than Firefox, Chrome, and Safari.
If you want the image-marker to be placed equally in all browsers, a crossbrowser solution is explained below.
Crossbrowser Solution
The following example displays the image-marker equally in all browsers:
Example
<html>
<head>
<style type="text/css">
ul
{
list-style-type:none;
padding:0px;
margin:0px;
}
li
{
background-image:url(your_image.gif);
background-repeat:no-repeat;
background-position:0px 5px;
padding-left:14px;
}
</style>
</head>
<body>
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
</body>
</html>
Try it yourself in Notepad or Dreamweaver by coping and pasting the code above.
Example explained:
- For ul:
- Set the list-style-type to none to remove the list item marker
- Set both padding and margin to 0px (for cross-browser compatibility)
- For li:
- Set the URL of the image, and show it only once (no-repeat)
- Position the image where you want it (left 0px and down 5px)
- Position the text in the list with padding-left
List - Shorthand property
It is also possible to specify all the list properties in one, single property. This is called a shorthand property.
The shorthand property used for lists, is the list-style property:
Example
<html>
<head>
<style type="text/css">
ul
{
list-style:square url("your_image.gif");
}
</style>
</head>
<body>
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
</body>
</html>
Try it yourself in Notepad or Dreamweaver by coping and pasting the code above.
When using the shorthand property, the order of the values are:
- list-style-type
- list-style-position (for a description, see the CSS properties table below)
- list-style-image
It does not matter if one of the values above are missing, as long as the rest are in the specified order.
More Examples
All the different list-item markers for lists
This example demonstrates all the different list-item markers in CSS.
Example
<html>
<head>
<style type="text/css">
ul.a {list-style-type:circle;}
ul.b {list-style-type:disc;}
ul.c {list-style-type:square;}
ol.d {list-style-type:armenian;}
ol.e {list-style-type:cjk-ideographic;}
ol.f {list-style-type:decimal;}
ol.g {list-style-type:decimal-leading-zero;}
ol.h {list-style-type:georgian;}
ol.i {list-style-type:hebrew;}
ol.j {list-style-type:hiragana;}
ol.k {list-style-type:hiragana-iroha;}
ol.l {list-style-type:katakana;}
ol.m {list-style-type:katagana-iroha;}
ol.n {list-style-type:lower-alpha;}
ol.o {list-style-type:lower-greek;}
ol.p {list-style-type:lower-latin;}
ol.q {list-style-type:lower-roman;}
ol.r {list-style-type:upper-alpha;}
ol.s {list-style-type:upper-latin;}
ol.t {list-style-type:upper-roman;}
ol.u {list-style-type:none;}
ol.v {list-style-type:inherit;}
</style>
</head>
<body>
<ul class="a">
<li>Circle type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
<ul class="b">
<li>Disc type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
<ul class="c">
<li>Square type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
<ol class="d">
<li>Armenian type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ol>
<ol class="e">
<li>Cjk-ideographic type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ol>
<ol class="f">
<li>Decimal type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ol>
<ol class="g">
<li>Decimal-leading-zero type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ol>
<ol class="h">
<li>Georgian type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ol>
<ol class="i">
<li>Hebrew type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ol>
<ol class="j">
<li>Hiragana type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ol>
<ol class="k">
<li>Hiragana-iroha type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ol>
<ol class="l">
<li>Katakana type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ol>
<ol class="m">
<li>Katakana-iroha type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ol>
<ol class="n">
<li>Lower-alpha type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ol>
<ol class="o">
<li>Lower-greek type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ol>
<ol class="p">
<li>Lower-latin type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ol>
<ol class="q">
<li>Lower-roman type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ol>
<ol class="r">
<li>Upper-alpha type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ol>
<ol class="s">
<li>Upper-latin type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ol>
<ol class="t">
<li>Upper-roman type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ol>
<ol class="u">
<li>None type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ol>
<ol class="v">
<li>inherit type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ol>
</body>
</html>
Try it yourself in Notepad or Dreamweaver by coping and pasting the code above.
Result:
- Circle type
- Tea
- Coca Cola
- Disc type
- Tea
- Coca Cola
- Square type
- Tea
- Coca Cola
- Armenian type
- Tea
- Coca Cola
- Cjk-ideographic type
- Tea
- Coca Cola
- Decimal type
- Tea
- Coca Cola
- Decimal-leading-zero type
- Tea
- Coca Cola
- Georgian type
- Tea
- Coca Cola
- Hebrew type
- Tea
- Coca Cola
- Hiragana type
- Tea
- Coca Cola
- Hiragana-iroha type
- Tea
- Coca Cola
- Katakana type
- Tea
- Coca Cola
- Katakana-iroha type
- Tea
- Coca Cola
- Lower-alpha type
- Tea
- Coca Cola
- Lower-greek type
- Tea
- Coca Cola
- Lower-latin type
- Tea
- Coca Cola
- Lower-roman type
- Tea
- Coca Cola
- Upper-alpha type
- Tea
- Coca Cola
- Upper-latin type
- Tea
- Coca Cola
- Upper-roman type
- Tea
- Coca Cola
- None type
- Tea
- Coca Cola
- inherit type
- Tea
- Coca Cola
All CSS List Properties
| Property | Description |
|---|---|
| list-style | Sets all the properties for a list in one declaration |
| list-style-image | Specifies an image as the list-item marker |
| list-style-position | Specifies if the list-item markers should appear inside or outside the content flow |
| list-style-type | Specifies the type of list-item marker |

