CSS Lists

Lists are a fundamental part of HTML and CSS, used to group a collection of items in a structured manner. CSS provides various properties to style lists and list items to enhance the visual presentation of web content.

Types of Lists

There are three primary types of lists in HTML:


Ordered List

An ordered list displays items in a specific sequence. By default, items are numbered, but you can customize the list style using CSS.

Try yourself
        
            ol {
   list-style-type: decimal;
   padding-left: 20px;
}
.ordered-list-example {
   margin-bottom: 20px;
}
        
    

Unordered List

An unordered list displays items without a specific sequence. By default, items are marked with bullets, but you can change the list style using CSS.

Try yourself
        
            ul {
    list-style-type: disc;
    padding-left: 20px;
}
.unordered-list-example {
    margin-bottom: 20px;
}
        
    

Description List

A description list is used to define terms and their descriptions. It consists of <dt> (definition term) and <dd> (definition description) elements.

Try yourself
        
            dl {
    margin: 20px 0;
}
dt {
    font-weight: bold;
}
dd {
    margin-left: 20px;
}
.description-list-example {
    margin-bottom: 20px;
}
        
    

List Style Type

The list-style-type property specifies the marker type for list items.

Try yourself
        
            .list-style-type-example ul {
    list-style-type: square;
}
.list-style-type-example ol {
    list-style-type: lower-alpha;
}
        
    

List Style Position

The list-style-position property specifies the position of the list item markers (bullet points or numbers).

Try yourself
        
            .list-style-position-example ul {
    list-style-position: inside;
}
.list-style-position-example ol {
    list-style-position: outside;
}
        
    

List Style Image

The list-style-image property allows you to specify an image as the list item marker.

Try yourself
        
            .list-style-image-example ul {
    list-style-image: url('/images/list-marker.png');
}
        
    

Removing List Styles

Sometimes you may want to remove the default list styles. You can do this using the list-style property.

Try yourself
        
            .remove-list-style-example ul, .remove-list-style-example ol {
    list-style: none;
    padding-left: 0;
}
        
    

Advanced List Styling

You can combine various CSS properties to create more advanced and customized list styles.

Try yourself
        
            .advanced-list-styling-example ul {
    list-style-type: circle;
    padding-left: 30px;
    color: blue;
    font-style: italic;
}
.advanced-list-styling-example ol {
    list-style-type: upper-roman;
    padding-left: 30px;
    color: green;
    font-weight: bold;
}
        
    

Practical Tips

Here are some practical tips for using CSS lists: