CSS Properties
CSS list-style Property
Photo Credit to CodeToFun
🙋 Introduction
The list-style
property in CSS is a shorthand property for setting all the list properties in one declaration. It can be used to control the appearance of list items, including the type of bullet or numbering, the position of the bullet, and an image to use as a marker.
This property is commonly used with unordered (<ul>) and ordered (<ol>) lists to enhance their presentation.
💡 Syntax
The syntax for the list-style
property allows you to set three sub-properties at once:
element {
list-style: list-style-type list-style-position list-style-image;
}
- list-style-type: Specifies the type of list item marker.
- list-style-position: Specifies the position of the list item marker.
- list-style-image: Specifies an image to be used as the list item marker.
🎛️ Default Value
The default value for the list-style property is disc outside none. This means that the list items will have a disc marker, the marker will be outside the list item, and no image will be used.
🏠 Property Values
- list-style-type:
- disc (default): Filled circle.
- circle: Hollow circle.
- square: Filled square.
- decimal: Numbers (1, 2, 3, ...).
- lower-alpha: Lowercase alphabet (a, b, c, ...).
- upper-alpha: Uppercase alphabet (A, B, C, ...).
- none: No marker.
- list-style-position:
- outside (default): Marker is outside the list item.
- inside: Marker is inside the list item.
- list-style-image:
- url(path/to/image): Specifies an image to use as the list item marker.
- none (default): No image is used.
📄 Example
In this example, we'll create a list with custom list-style
properties.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS list-style Example</title>
<style>
ul.custom-list {
list-style: square inside url('marker.png');
}
</style>
</head>
<body>
<h1>Custom List Style Example</h1>
<ul class="custom-list">
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
</ul>
</body>
</html>
In this example:
- list-style-type is set to square.
- list-style-position is set to inside.
- list-style-image is set to an image located at marker.png.
🖥️ Browser Compatibility
The list-style
property is supported in all modern browsers, including Chrome, Firefox, Safari, Edge, and Opera. It is widely used and has broad compatibility, making it a reliable choice for styling lists.
🎉 Conclusion
The list-style
property in CSS provides a simple way to customize the appearance of list items.
By adjusting the type, position, and image of the list markers, you can create visually appealing lists that fit the design of your website. Experiment with different values and combinations to achieve the desired look for your lists.
👨💻 Join our Community:
Author
For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.
Buy me a coffee to make codetofun.com free for everyone.
Buy me a Coffee
If you have any doubts regarding this article (CSS list-style Property), please comment here. I will help you immediately.