How to add an image as the list-item marker in a list using CSS?


CSS, the acronym for cascading style sheets, is a straightforwardly built language that makes it easier to present web pages. Applying styles to web pages is possible with CSS.  In this article we are going to see how we can use CSS to add an image as the list-item marker in a list.

Approach

We are going to make use of the list-style-image property to accomplish the task. The list-style-image property allows the user to set an image as the list-item marker in a list.

Syntax

list-style-image: none | url | initial | inherit;

Example

Step 1 − First we will define the HTML code.

<!DOCTYPE html>
<html>
<head>
   <title>How to add an image as the list-item marker in a list using CSS?</title>
</head>
<body>
   <h4>How to add an image as the list-item marker in a list using CSS?</h4>
   <div>
      <ul>
         <li>Item 1</li>
         <li>Item 2</li>
         <li>Item 3</li>
      </ul>
   </div>
</body>
</html>

Step 2 − Now we will add the CSS logic.

<style>
   ul{
      list-style-image: url("https://www.tutorialspoint.com/images/logo.png");
      padding-left: 350px;
   }
</style>

Here is the complete code −

<!DOCTYPE html>
<html>
<head>
   <title>How to add an image as the list-item marker in a list using CSS?</title>
   <style>
      ul {
         list-style-image: url("https://www.tutorialspoint.com/images/logo.png");
         padding-left: 350px;
      }
   </style>
</head>
<body>
   <h4>How to add an image as the list-item marker in a list using CSS?</h4>
   <div>
      <ul>
         <li>Item 1</li>
         <li>Item 2</li>
         <li>Item 3</li>
      </ul>
   </div>
</body>
</html>

Conclusion

In this article, we saw how with the help of the list-style-image property in CSS we could set an image as the list-item marker in a list.

Updated on: 30-Mar-2023

803 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements