Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Properties

CSS list-style Property

Posted in CSS Tutorial
Updated on Oct 03, 2024
By Mari Selvan
👁️ 12 - Views
⏳ 4 mins
💬 1 Comment
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:

Syntax
Copied
Copy To Clipboard
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

  1. 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.
  2. list-style-position:
    • outside (default): Marker is outside the list item.
    • inside: Marker is inside the list item.
  3. 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.

index.html
Copied
Copy To Clipboard
<!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:

To get interesting news and instant updates on Front-End, Back-End, CMS and other Frameworks. Please Join the Telegram Channel:

Author

author
👋 Hey, I'm Mari Selvan

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

Share Your Findings to All

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
We make use of cookies to improve our user experience. By using this website, you agree with our Cookies Policy
AgreeCookie Policy