Working with Lists
- To work with the list-style-type property.
- To work with the list-style-position property.
- To work with the list-style-image property.
List-style-type
The list-style-type property is used to specify if and how the list item marker should appear.
The values for unordered lists are glyphs. The values are listed below.
- disc
- circle
- square
The values for ordered lists are numbering or alphabetic systems. The well-supported values are listed below.
- decimal
- lower-roman
- upper-roman
- lower-alpha
- upper-alpha
The list-style-type property can also be set to none, in which case no list item marker will be used.
Code Sample: Lists/Demos/Lists.html
<html>
<head>
<title>CSS List</title>
<style type="text/css">
ol {
list-style-type:upper-roman;
font-weight:bold;
font-style:normal;
font-size:x-large;
}
ol ol {
list-style-type:upper-alpha;
font-weight:bold;
font-style:italic;
font-size:smaller;
}
ol ol ol {
list-style-type:decimal;
font-weight:normal;
font-style:normal;
}
ol ol ol ol {
list-style-type:lower-roman;
font-weight:normal;
font-style:italic;
}
ol ol ol ol ol {
list-style-type:lower-alpha;
font-weight:normal;
font-style:normal;
}
ul {
list-style-type:disc;
font-weight:bold;
font-style:normal;
font-size:x-large;
}
ul ul {
list-style-type:circle;
font-weight:bold;
font-style:italic;
font-size:smaller;
}
ul ul ul {
list-style-type:square;
font-weight:normal;
font-style:normal;
}
ul ul ul ul {
list-style-type:disc;
font-weight:normal;
font-style:italic;
}
ul ul ul ul ul {
list-style-type:circle;
font-weight:normal;
font-style:normal;
}
</style>
</head>
<body>
<h2>Ordered list</h2>
<ol>
<li>Level 1
<ol>
<li>Level 2</li>
<li>Level 2
<ol>
<li>Level 3</li>
<li>Level 3
<ol>
<li>Level 4</li>
<li>Level 4
<ol>
<li>Level 5</li>
<li>Level 5</li>
<li>Level 5</li>
</ol>
</li>
<li>Level 4</li>
<li>Level 4</li>
</ol>
</li>
<li>Level 3</li>
<li>Level 3</li>
</ol>
</li>
<li>Level 2</li>
<li>Level 2</li>
</ol>
</li>
<li>Level 1
<ol>
<li>Level 2</li>
<li>Level 2
<ol>
<li>Level 3</li>
<li>Level 3
<ol>
<li>Level 4</li>
<li>Level 4
<ol>
<li>Level 5</li>
<li>Level 5</li>
<li>Level 5</li>
</ol>
</li>
<li>Level 4</li>
<li>Level 4</li>
</ol>
</li>
<li>Level 3</li>
<li>Level 3</li>
</ol>
</li>
<li>Level 2</li>
<li>Level 2</li>
</ol>
</li>
</ol>
<h2>Unordered List</h2>
<ul>
<li>Level 1
<ul>
<li>Level 2</li>
<li>Level 2
<ul>
<li>Level 3</li>
<li>Level 3
<ul>
<li>Level 4</li>
<li>Level 4
<ul>
<li>Level 5</li>
<li>Level 5</li>
<li>Level 5</li>
</ul>
</li>
<li>Level 4</li>
<li>Level 4</li>
</ul>
</li>
<li>Level 3</li>
<li>Level 3</li>
</ul>
</li>
<li>Level 2</li>
<li>Level 2</li>
</ul>
</li>
<li>Level 1
<ul>
<li>Level 2</li>
<li>Level 2
<ul>
<li>Level 3</li>
<li>Level 3
<ul>
<li>Level 4</li>
<li>Level 4
<ul>
<li>Level 5</li>
<li>Level 5</li>
<li>Level 5</li>
</ul>
</li>
<li>Level 4</li>
<li>Level 4</li>
</ul>
</li>
<li>Level 3</li>
<li>Level 3</li>
</ul>
</li>
<li>Level 2</li>
<li>Level 2</li>
</ul>
</li>
</ul>
</body>
</html>
The screenshots below show how the above code gets output to the browser.
![]()
![]()
List-style-position
The list-style-position is used to specify whether the list item marker should be left-aligned with the second and subsequent lines in the list item. The values are inside (aligned with subsequent lines) and outside (bumped to the left). The following code illustrates how list-style-position works.
Code Sample: Lists/Demos/ListStylePosition.html
<html> <head> <title>CSS List Style Position</title> </head> <body> <h1>CSS List Style Position</h1> <ul style="list-style-position:inside;"> <li>When list-style-position is set to inside, the list item marker aligns with line 2 and subsequent lines in the list item.</li> </ul> <ul style="list-style-position:outside;"> <li>When list-style-position is set to outside, the list item marker does not align with line 2 and subsequent lines in the list item. Rather, it gets bumped to the left.</li> </ul> </body> </html>
The code above will render as follows.
![]()
List-style-image
The list-style-image is used to specify an image to be used as the list item marker. The syntax is shown below.
selector {
list-style-image:url(url);
}Code Sample: Lists/Demos/ListImages.html
<html>
<head>
<title>CSS Image List</title>
<style type="text/css">
ul.imageList {
list-style-image:url(Images/bullet1.gif);
font-weight:bold;
font-style:normal;
font-size:x-large;
}
ul.imageList ul {
list-style-image:url(Images/bullet2.gif);
font-weight:bold;
font-style:italic;
font-size:smaller;
}
ul.imageList ul ul {
list-style-image:url(Images/bullet3.gif);
font-weight:normal;
font-style:normal;
}
ul.imageList ul ul ul {
list-style-image:url(Images/bullet4.gif);
font-weight:normal;
font-style:italic;
}
ul.imageList ul ul ul ul {
list-style-image:url(Images/bullet5.gif);
font-weight:normal;
font-style:normal;
}
</style>
</head>
<body>
<h1>CSS Image List</h1>
<ul class="imageList">
<li>Level 1
<ul>
<li>Level 2</li>
<li>Level 2
<ul>
<li>Level 3</li>
<li>Level 3
<ul>
<li>Level 4</li>
<li>Level 4
<ul>
<li>Level 5</li>
<li>Level 5</li>
<li>Level 5</li>
</ul>
<li>Level 4</li>
<li>Level 4</li>
</ul>
<li>Level 3</li>
<li>Level 3</li>
</ul>
<li>Level 2</li>
<li>Level 2</li>
</ul>
<li>Level 1</li>
<ul>
<li>Level 2</li>
<li>Level 2
<ul>
<li>Level 3</li>
<li>Level 3
<ul>
<li>Level 4</li>
<li>Level 4
<ul>
<li>Level 5</li>
<li>Level 5</li>
<li>Level 5</li>
</ul>
<li>Level 4</li>
<li>Level 4</li>
</ul>
<li>Level 3</li>
<li>Level 3</li>
</ul>
<li>Level 2</li>
<li>Level 2</li>
</ul>
</ul>
</body>
</html>
The above code will render the following.
![]()
Working with Lists Conclusion
In this lesson of the CSS tutorial, you have learned to use CSS list properties.
