129

I need to use, for example, the star-symbol(★) as the bullet for a list-item.

I have read the CSS3 module: Lists, that describes, how to use custom text as bullets, but it's not working for me. I think, the browsers simply don't support the ::marker pseudo element.

How can I do it, without using images?

Nisse Engström
  • 4,738
  • 23
  • 27
  • 42
AntonAL
  • 16,692
  • 21
  • 80
  • 114
  • can you put up the code you're using? And what browser are you testing this in? – Jonny Haynes Jul 08 '10 at 12:04
  • 1
    http://stackoverflow.com/questions/3068199/which-character-is-used-to-fill-contents-of-password-text-input/3068265#3068265 has some Unicode bullets. Neither the star symbol you have above, nor 26AB (medium black circle) display on my Windows machine, though they are OK on Ubuntu. – Pete Kirkham Jul 08 '10 at 12:11
  • This answer (to a similar question) solved it for me: http://stackoverflow.com/a/12216973/907575 – Piotr Migdal May 28 '15 at 11:49

14 Answers14

118

Using Text As Bullets

Use li:before with an escaped Hex HTML Entity (or any plain text).


Example

My example will produce lists with check marks as bullets.

ul {
    list-style: none;
    padding: 0px;
}

ul li:before
{
    content: '\2713';
    margin: 0 1em;    /* any design */
}
<ul>
  <li>First item</li>
  <li>Second item</li>
</ul>

Browser Compatibility

Haven't tested myself, but it should be supported as of IE8. At least that's what quirksmode & css-tricks say.

You can use conditional comments to apply older/slower solutions like images, or scripts. Better yet, use both with <noscript> for the images.

HTML:

<!--[if lt IE 8]>
    *SCRIPT SOLUTION*
    <noscript>
        *IMAGE SOLUTION*
    </noscript>
<![endif]-->

About background images

Background images are indeed easy to handle, but...

  1. Browser support for background-size is actually only as of IE9.
  2. HTML text colors and special (crazy) fonts can do a lot, with less HTTP requests.
  3. A script solution can just inject the HTML Entity, and let the same CSS do the work.
  4. A good resetting CSS code might make list-style (the more logical choice) easier.

Enjoy.

Flimm
  • 136,138
  • 45
  • 251
  • 267
222
  • 1,257
  • 2
  • 8
  • 4
  • 1
    useful conversion tool for escaping special characters http://rishida.net/tools/conversion/ – iiz Jan 22 '13 at 11:25
  • 27
    This does not work properly if the contents of the `li` element wrap over multiple lines; those wrapped lines will not be indented correctly. – Richard Ev Aug 21 '13 at 08:05
  • 5
    `float: left; margin-left: -12px;` on the :before to take care of that, @RichardEverett – Dudo Mar 18 '15 at 20:27
  • 1
    I works for one line but doesn't work if several lines are wrapping. – VDarricau Aug 17 '15 at 23:08
  • i don't know if this works everywhere equally, but i got best results with: `margin-right: 0.5em; margin-left:-1.5em;` it looks like the star is exactly 1em in width because multiple lines now line up perfectly. so i guess the general rule would be: `margin-left` = `- (margin-right + width of character)` – eMBee Nov 07 '16 at 14:45
  • 1
    Works only for single-line list-items. Multi-lines will drop beneath the bullet rather than indenting. – Clarus Dignus Mar 30 '18 at 22:03
85

EDIT

I probably wouldn't recommend using images anymore. I'd stick to the approach of using a Unicode character, like this:

li:before {
  content: "\2605";
}

OLD ANSWER

I'd probably go for an image background, they're much more efficient versatile and cross-browser-friendly.

Here's an example:

<style type="text/css">
  ul {list-style:none;} /* you should use a css reset too... ;) */
  ul li {background:url(images/icon_star.gif) no-repeat 0 5px;}
</style>

<ul>
  <li>List Item 1</li>
  <li>List Item 2</li>
  <li>List Item 3</li>
</ul>
whallz
  • 2,365
  • 2
  • 22
  • 24
  • 49
    How is that “much more efficient”? You’re sending an additional HTTP request to fetch the image and the total file increases as you load an image for something that could just be done through the use of a single Unicode character. – Mathias Bynens Jul 06 '11 at 05:22
  • 2
    you're right, probably "efficient" is not the word i should have used if you're looking for performance, but using an image background is certainly much more versatile than using text. – whallz Aug 25 '11 at 13:30
  • 3
    It's not very good to resize an image, but a character is perfect on every size, so I would say a character is more versatile :P I think backword-compatible or with widest range of browser support would be the word... – justGoscha Aug 04 '14 at 12:03
  • 1
    This doesn't work well when the `
  • ` text wraps: The bullet doesn't remain unindented, and ends up looking like the beginning of a paragraph of text. This answer fixes this issue: https://stackoverflow.com/a/14301918/1450294
  • – Michael Scheper May 24 '19 at 19:53