list-style-image

Term side of the Card.
Topic: Lists
Unit title: list-style-image
Categories: Property
Explanation side of the Card

Explanation: The property that sets an image to be used as the marker for list items. Instead of the default bullets or numbers, a custom image can be used, providing a unique look to ordered or unordered lists.

Browser compatibility:
  • The chrome browser supports this feature starting from version 1.
  • The edge browser supports this feature starting from version 12.
  • The firefox browser supports this feature starting from version 1.
  • The safari browser supports this feature starting from version 1.
Availability: 

Example

Wrongcss
li {
  list-style-image: url("check-large.png");
}
Rightcss
li {
  list-style: none;
  padding-inline-start: 1.5em;
  background: url("check.svg") no-repeat 0 0.2em / 1em;
}

list-style-image shows the image at its natural size, so a background gives control over size and position.

Common mistakes

  • The bullet image is too big and there is no way to scale it.

Key points

  • Bullet images that need a set size use ::marker, ::before or a background, since list-style-image cannot be resized.
  • A list-style-type fallback is kept for when the image fails to load.
  • Decorative bullet images carry no meaning that must be read aloud.

Interview questions

Can I change the size of list-style-image?

No. The image is shown at its natural size. Use an SVG drawn at the right size, or a background or ::before image instead.

Can I use an SVG for list-style-image?

Yes. Any image URL works, and an SVG with set width and height gives a crisp, predictable bullet.

Analytics cookiesWe'd like to use analytics cookies to see which pages are useful. They're set only if you accept. Privacy Policy