{"id":298638,"date":"2019-11-14T08:21:11","date_gmt":"2019-11-14T15:21:11","guid":{"rendered":"https:\/\/css-tricks.com\/?p=298638"},"modified":"2019-12-19T06:46:47","modified_gmt":"2019-12-19T13:46:47","slug":"finally-it-will-be-easy-to-change-the-color-of-list-bullets","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/finally-it-will-be-easy-to-change-the-color-of-list-bullets\/","title":{"rendered":"Finally, it Will Be Easy to Change the Color of List Bullets"},"content":{"rendered":"

In my germinating years, the general advice was this:<\/p>\n

<ul>\r\n  <li><span>List item<\/span><\/li>\r\n  <!-- ... -->\r\n<\/ul><\/code><\/pre>\n
li { color: red; } \/* bullet *\/\r\nli span { color: black; } \/* text *\/<\/code><\/pre>\n

Not terrible, but not great. You’re “resetting” everything at the span level, so it gets more complicated the more you do. <\/p>\n

Things are getting much easier. Let’s take a walk through this world getting more modern as we go.<\/p>\n

<\/p>\n


\n

An alternative was to rip off the default list styling and replace it with a pseudo-element.<\/p>\n

ul {\r\n  list-style: none;\r\n}\r\n\r\nli::before {\r\n  content: \"\u2022 \";\r\n  color: red;\r\n}<\/code><\/pre>\n

If we need to count, we could do that with CSS counters<\/a>. <\/p>\n

ol {\r\n  list-style: none;\r\n  counter-reset: my-awesome-counter;\r\n}\r\n\r\nol li {\r\n  counter-increment: my-awesome-counter;\r\n}\r\n\r\nol li::before {\r\n  content: counter(my-awesome-counter) \". \";\r\n  color: red;\r\n}<\/code><\/pre>\n
\n

Quick aside here: this doesn’t help with the color, but you can specify what character to use for the bullet by setting a string, like:<\/p>\n

ul {\r\n  list-style-type: '\u273d ';\r\n}<\/code><\/pre>\n

This is as of Firefox 39 (2015) and Chrome 79 (which comes out Dec 9, 2019<\/a>). <\/p>\n

For ordered lists, there is a ton of language-specific options<\/a>. And those language styles work for CSS counters as well, which you can learn more about in Hui Jing’s deep dive<\/a>. <\/p>\n

\n See the Pen
\n Random CSS counters playground<\/a> by Chen Hui Jing (
@huijing<\/a>)
\n on
CodePen<\/a>.<\/span>\n<\/p>\n


\n

But all the while, we only wanted to select the stupid bullet (or whatever it is) and style it. Now we are starting to be able to do just that.<\/p>\n

As of Firefox 68 (July 2019), you can do like:<\/p>\n

li::marker {\r\n  color: red;\r\n  content: \"\u25ba\";\r\n}<\/code><\/pre>\n

…which, as you can see, changes the color and the bullet thing That is definitely the cleanest and easiest way to go, so it’s nice to see progress.<\/p>\n

Tejas demonstrates:<\/p>\n

\n See the Pen
\n ::marker example<\/a> by Tejas (
@tejask<\/a>)
\n on
CodePen<\/a>.<\/span>\n<\/p>\n

Manuel Matuzovi\u0107 notes<\/a> that if you set an element to a list-item<\/code> display type, you can use markers on them as well.<\/p>\n

h2 {\r\n  display: list-item;\r\n}\r\n\r\nh2::marker {\r\n  color: orange;\r\n  content: \"\u261e\";\r\n}<\/code><\/pre>\n

Even Safari has support at the time of this writing, so we should lean on Chrome<\/a> here.<\/p>\n

This browser support data is from Caniuse<\/a>, which has more detail. A number indicates that browser supports the feature at that version and up.<\/p><\/div>

Desktop<\/h4>
Chrome<\/span><\/th>Firefox<\/span><\/th>IE<\/span><\/th>Edge<\/span><\/th>Safari<\/span><\/th><\/tr><\/thead>
86<\/span><\/td>68<\/span><\/td>No<\/span><\/td>86<\/span><\/td>11.1<\/span><\/td><\/tr><\/table><\/div>

Mobile \/ Tablet<\/h4>
Android Chrome<\/span><\/th>Android Firefox<\/span><\/th>Android<\/span><\/th>iOS Safari<\/span><\/th><\/tr><\/thead>
124<\/span><\/td>125<\/span><\/td>124<\/span><\/td>11.3-11.4<\/span><\/td><\/tr><\/table><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"

In my germinating years, the general advice was this: <ul> <li><span>List item<\/span><\/li> <!– … –> <\/ul> li { color: red; } \/* bullet *\/ li span { color: black; } \/* text *\/ Not terrible, but not great. You’re “resetting” everything at the span level, so it gets more complicated the more you do. Things […]<\/p>\n","protected":false},"author":3,"featured_media":298702,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"inline_featured_image":false,"c2c_always_allow_admin_comments":false,"footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":[]},"categories":[4],"tags":[969],"jetpack_publicize_connections":[],"acf":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/css-tricks.com\/wp-content\/uploads\/2019\/11\/shapes-and-stuff.png?fit=1200%2C600&ssl=1","jetpack-related-posts":[{"id":248040,"url":"https:\/\/css-tricks.com\/style-list-markers-css\/","url_meta":{"origin":298638,"position":0},"title":"Style List Markers in CSS","date":"November 21, 2016","format":false,"excerpt":"It's a perfectly reasonable to want to style the marker of list items. You know: blue bullets with black text in an unordered list. Or red counters with knockout white numbers in an ordered list. There is a working draft spec that defines a ::marker pseudo-element that would give us\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/css-tricks.com\/wp-content\/uploads\/2016\/11\/styled-list-items.png?fit=1200%2C600&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":312104,"url":"https:\/\/css-tricks.com\/how-to-reverse-css-custom-counters\/","url_meta":{"origin":298638,"position":1},"title":"How to Reverse CSS Custom Counters","date":"June 11, 2020","format":false,"excerpt":"I needed a numbered list of blog posts to be listed with the last\/high first and going down from there. Like this: 5. Post Title 4. Post Title 3. Post Title 2. Post Title 1. Post Title But the above is just text. I wanted to do this with a\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/css-tricks.com\/wp-content\/uploads\/2020\/06\/css-counter-reversed.png?fit=1200%2C600&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":316298,"url":"https:\/\/css-tricks.com\/how-to-make-a-list-component-with-emotion\/","url_meta":{"origin":298638,"position":2},"title":"How to Make a List Component with Emotion","date":"July 8, 2020","format":false,"excerpt":"I\u2019ve been doing a bit of refactoring this week at Sentry and I noticed that we didn\u2019t have a generic List component that we could use across projects and features. So, I started one, but here\u2019s the rub: we style things at Sentry using Emotion, which I have only passing\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/css-tricks.com\/wp-content\/uploads\/2020\/07\/emotion-lists.png?fit=1200%2C600&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":365888,"url":"https:\/\/css-tricks.com\/a-perfect-table-of-contents-with-html-css\/","url_meta":{"origin":298638,"position":3},"title":"A Perfect Table of Contents With HTML + CSS","date":"May 25, 2022","format":false,"excerpt":"Earlier this year, I self-published an ebook called Understanding JavaScript Promises (free for download). Even though I didn't have any intention of turning it into a print book, enough people reached out inquiring about a print version that I decided to self-publish that as well .I thought it would be\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/css-tricks.com\/wp-content\/uploads\/2022\/05\/toc-photo-scaled.jpg?fit=1200%2C812&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":375273,"url":"https:\/\/css-tricks.com\/newer-things-to-know-about-good-ol-html-lists\/","url_meta":{"origin":298638,"position":4},"title":"Newer Things to Know About Good Ol\u2019 HTML Lists","date":"November 28, 2022","format":false,"excerpt":"HTML lists are boring. They don\u2019t do much, so we don\u2019t really think about them despite how widely used they are. And we\u2019re still able to do the same things we\u2019ve always done to customize them, like removing markers, reversing order, and making custom counters. There are, however, a few\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/css-tricks.com\/wp-content\/uploads\/2022\/11\/html-lists.jpg?fit=1200%2C600&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":3058,"url":"https:\/\/css-tricks.com\/different-ways-to-format-css\/","url_meta":{"origin":298638,"position":5},"title":"Different Ways To Format CSS","date":"July 13, 2009","format":false,"excerpt":"This post will focus on the different ways to format CSS, which differs from the different ways to organize CSS. Definitely related concepts, but I think organization has more to do with how things are grouped and ordered while formatting has to do with spacing and indenting. Formatting has nothing\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"featured_media_src_url":"https:\/\/i0.wp.com\/css-tricks.com\/wp-content\/uploads\/2019\/11\/shapes-and-stuff.png?fit=1024%2C512&ssl=1","_links":{"self":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/posts\/298638"}],"collection":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/comments?post=298638"}],"version-history":[{"count":10,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/posts\/298638\/revisions"}],"predecessor-version":[{"id":300911,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/posts\/298638\/revisions\/300911"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/media\/298702"}],"wp:attachment":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/media?parent=298638"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/categories?post=298638"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/tags?post=298638"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}