DEV Community

Cover image for Use Unicode characters for bullet points in CSS using ::marker
Cassidy Williams
Cassidy Williams

Posted on • Edited on • Originally published at cassidoo.co

Use Unicode characters for bullet points in CSS using ::marker

I was playing around with making some <ul>s on an HTML page recently, and typically when I want to replace the bullet points with an emoji or an SVG or something, I'll write something like:

ul { list-style-type: none; }
ul li:before { content:"\2713"; }
Enter fullscreen mode Exit fullscreen mode

And this works, but for longer lines of text, you get some spacing issues. You can fix it by changing the padding around the list and messing with the positioning, but that's a lot of trial and error.

Enter, the ::marker psuedo-element!

This is a really cool, relatively new option to solve our problem! It selects the marker box of a list item (so the bullet, or a number if you're using ol), and you can change the font properties, the color, and some other things around it!

Demo:

It's not fully compatible with Internet Explorer, and some other older versions of modern browsers. You can check the compatibility table here, and the documentation for it here!

Latest comments (21)

Collapse
 
yuridevat profile image
Julia 👩🏻‍💻 GDE

Unfortunately it is not possible (for now) to change its position to align it centered/baseline to the text 😕
I really hope font-size-adjust will be compatible not only for Firefox soon 🙏

Collapse
 
russellbateman profile image
Russell Bateman

Interesting. I only get the usual bullets in Google Chrome 100.0.4896.75 running on Linux.

Collapse
 
russellbateman profile image
Russell Bateman

(Oops, sorry. I had left the comments in the CSS.)

Collapse
 
netlancer profile image
Ellie

Pretty cool, and probably we can still use the older technic as a fallback for IE &likes.
Thank you :))

Collapse
 
jackplug profile image
Stuart Homfray

I notice that a few paople are mentioning IE (11) support. Obviously, it does not support ::marker, as everyone realises, but is that REALLY a problem here?? We (my company) support IE11, but we do not expect it to render everything in the same way as modern browsers. As long as the page is still usable/understandable, then everything should be fine.

::marker is a great example of this: modern browsers get the fancy markers; those stuck with non-supporting browsers get default bullet-style markers 👍

Collapse
 
greensleeves01 profile image
VidelicetWDC

Very nice!

Collapse
 
vfcc profile image
vfcc

Thank you so much, I've learned something new today.

Collapse
 
getsetgopi profile image
GP

Nice! Will try it out. I know lots of organization, including mine are still supporting IE11 to maintain legacy applications. Having said, IE11 is EOL and we can start using these new features.

Collapse
 
webbureaucrat profile image
webbureaucrat

I recall staring longingly at the CanIUse page for this feature a few years ago. Glad to hear it's widely implemented! Thank you for sharing!

Collapse
 
capscode profile image
capscode

Thanks for sharing this.
I have never tried this but will use it in my next project..

Collapse
 
pablowbk profile image
Pablo

This is neat, thanks!