Formatting Unordered and Ordered Lists in CSS



The style and position of unordered and ordered lists can be formatted by CSS properties with list-style-type, list-style-image and list-style-position.

Syntax

The syntax of CSS list-style property is as follows −

Selector {
   list-style: /*value*/
}

Example

The following examples illustrate CSS list-style property −

The following example styles ordered list −

 Live Demo

<!DOCTYPE html>
<html>
<head>
<style>
ol {
   list-style: upper-roman;
   line-height: 150%;
}
</style>
</head>
<body>
<h2>Latest C# Versions</h2>
<ol>
<li>C# 8.0</li>
<li>C# 7.3</li>
<li>C# 7.2</li>
<li>C# 7.1</li>
<li>C# 7.0</li>
</ol>
</body>
</html>

Output

This gives the following output −

Example

The following example styles unordered list −

 Live Demo

<!DOCTYPE html>
<html>
<head>
<style>
ul > ul{
   list-style: circle inside;
}
li:last-child {
   list-style-type: square;
}
</style>
</head>
<body>
<h2>Programming Languages</h2>
<ul>
<li>C++ programming language created by Bjarne Stroustrup as an extension of the C programming language.</li>
<li>Java programming language developed by James Gosling.</li>
<ul>
<li>Core Java</li>
<li>Advanced Java</li>
</ul>
<li>Scala is a modern multi-paradigm programming language designed to express common programming patterns in a concise, elegant, and type-safe way.</li>
</ul>
</body>
</html>

Output

This gives the following output −


Advertisements