{"id":384529,"date":"2025-03-17T10:25:04","date_gmt":"2025-03-17T16:25:04","guid":{"rendered":"https:\/\/css-tricks.com\/?p=384529"},"modified":"2025-05-30T09:17:32","modified_gmt":"2025-05-30T15:17:32","slug":"styling-counters-in-css","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/styling-counters-in-css\/","title":{"rendered":"Styling Counters in CSS"},"content":{"rendered":"\n
\n
\n
\n
\n

Yes, you are reading that correctly: This is indeed a guide to styling counters with CSS. Some of you are cheering, “Finally!”, but I understand that the vast majority of you are thinking, “Um, it’s just styling lists.” If you are part of the second group, I get it. Before learning and writing more and more about counters, I thought the same thing. Now I am part of the first group, and by the end of this guide, I hope you join me there.<\/p>\n\n\n\n

There are many<\/em> ways to create and style counters, which is why I wanted to write this guide and also how I plan to organize it: going from the most basic styling to the top-notch level of customization, sprinkling in between some sections about spacing and accessibility. It isn’t necessary to read the guide in order \u2014 each section should stand by itself, so feel free to jump to any part and start reading.<\/p>\n<\/div>\n\n\n\n

Table of Contents<\/h2>\n\n\n
    \n
  1. HTML Based Customization<\/a><\/li>\n\n\n\n
  2. Styling Simple Counters in CSS<\/a><\/li>\n\n\n\n
  3. Custom Counters<\/a><\/li>\n\n\n\n
  4. Custom Counters Styles<\/a><\/li>\n\n\n\n
  5. Images in Counters<\/a><\/li>\n\n\n\n
  6. Spacing Things out<\/a><\/li>\n\n\n\n
  7. Accessibility<\/a><\/li>\n\n\n\n
  8. Almanac references<\/a><\/li>\n\n\n\n
  9. Further reading<\/a><\/li>\n<\/ol>\n<\/div>\n<\/div>\n\n\n\n
    <\/div>\n<\/div>\n<\/div>\n\n\n\n
    \n \n

    Customizing Counters in HTML<\/h2>\n <\/summary>\n \n\n
    \n
    \n

    Lists elements were among the first 18 tags that made up HTML<\/a>. Their representation wasn’t defined yet but deemed fitting a bulleted list for unordered lists, and a sequence of numbered paragraphs for an ordered list.<\/p>\n\n\n\n

    Cool but not enough; soon people needed more from HTML alone and new list attributes<\/strong> were added throughout the years to fill in the gaps.<\/p>\n<\/div>\n<\/div>\n\n\n\n

    \n

    start<\/code><\/h3>\n\n\n

    The start<\/code> attribute takes an integer and sets from where the list should start:<\/p>\n\n\n\n

    <ol start=\"2\">\n  <li>Bread<\/li>\n  <li>Milk<\/li>\n  <li>Butter<\/li>\n  <li>Apples<\/li>\n<\/ol><\/code><\/pre>\n\n\n\n
      \n
    1. Bread<\/li>\n\n\n\n
    2. Milk<\/li>\n\n\n\n
    3. Butter<\/li>\n\n\n\n
    4. Apples<\/li>\n<\/ol>\n\n\n\n

      Although, it isn’t limited to positive values; zero and negative integers are allowed as well:<\/p>\n\n\n\n

      <ol start=\"0\">\n  <li>Bread<\/li>\n  <li>Milk<\/li>\n  <li>Butter<\/li>\n  <li>Apples<\/li>\n<\/ol>\n\n<ol start=\"-2\">\n  <li>Bread<\/li>\n  <li>Milk<\/li>\n  <li>Butter<\/li>\n  <li>Apples<\/li>\n<\/ol><\/code><\/pre>\n\n\n\n
      \n
      \n
        \n
      1. Bread<\/li>\n\n\n\n
      2. Milk<\/li>\n\n\n\n
      3. Butter<\/li>\n\n\n\n
      4. Apples<\/li>\n<\/ol>\n<\/div>\n\n\n\n
        \n
          \n
        1. Bread<\/li>\n\n\n\n
        2. Milk<\/li>\n\n\n\n
        3. Butter<\/li>\n\n\n\n
        4. Apples<\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n\n\n\n

          type<\/code><\/h3>\n\n\n

          We can use the type<\/code> attribute to change the counter’s representation. It’s similar to CSS’s list-style-type<\/code>, but it has its own limited uses and shouldn’t be used interchangeably*. Its possible values are:<\/p>\n\n\n\n