Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      June 2, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      June 2, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      June 2, 2025

      How To Prevent WordPress SQL Injection Attacks

      June 2, 2025

      The Alters: Release date, mechanics, and everything else you need to know

      June 2, 2025

      I’ve fallen hard for Starsand Island, a promising anime-style life sim bringing Ghibli vibes to Xbox and PC later this year

      June 2, 2025

      This new official Xbox 4TB storage card costs almost as much as the Xbox SeriesXitself

      June 2, 2025

      I may have found the ultimate monitor for conferencing and productivity, but it has a few weaknesses

      June 2, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      May report 2025

      June 2, 2025
      Recent

      May report 2025

      June 2, 2025

      Write more reliable JavaScript with optional chaining

      June 2, 2025

      Deploying a Scalable Next.js App on Vercel – A Step-by-Step Guide

      June 2, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      The Alters: Release date, mechanics, and everything else you need to know

      June 2, 2025
      Recent

      The Alters: Release date, mechanics, and everything else you need to know

      June 2, 2025

      I’ve fallen hard for Starsand Island, a promising anime-style life sim bringing Ghibli vibes to Xbox and PC later this year

      June 2, 2025

      This new official Xbox 4TB storage card costs almost as much as the Xbox SeriesXitself

      June 2, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»Some Things You Might Not Know About Custom Counter Styles

    Some Things You Might Not Know About Custom Counter Styles

    January 23, 2025

    I was reading through Juan’s recent Almanac entry for the @counter-style at-rule and I’ll be darned if he didn’t uncover and unpack some extremely interesting things that we can do to style lists, notably the list marker. You’re probably already aware of the ::marker pseudo-element. You’ve more than likely dabbled with custom counters using counter-reset and counter-increment. Or maybe your way of doing things is to wipe out the list-style (careful when doing that!) and hand-roll a marker on the list item’s ::before pseudo.

    But have you toyed around with @counter-style? Turns out it does a lot of heavy lifting and opens up new ways of working with lists and list markers.

    You can style the marker of just one list item

    This is called a “fixed” system set to a specific item.

    @counter-style style-fourth-item {
      system: fixed 4;
      symbols: "💠";
      suffix: " ";
    }
    
    li {
      list-style: style-fourth-item;
    }
    CodePen Embed Fallback

    You can assign characters to specific markers

    If you go with an “additive” system, then you can define which symbols belong to which list items.

    @counter-style dice {
      system: additive;
      additive-symbols: 6 "⚅", 5 "⚄", 4 "⚃", 3 "⚂", 2 "⚁", 1 "⚀";
      suffix: " ";
    }
    
    li {
      list-style: dice;
    }
    CodePen Embed Fallback

    Notice how the system repeats once it reaches the end of the cycle and begins a new series based on the first item in the pattern. So, for example, there are six sides to typical dice and we start rolling two dice on the seventh list item, totaling seven.

    You can add a prefix and suffix to list markers

    A long while back, Chris showed off a way to insert punctuation at the end of a list marker using the list item’s ::before pseudo:

    ol {
      list-style: none;
      counter-reset: my-awesome-counter;
    
      li {
        counter-increment: my-awesome-counter;
    
        &::before {
          content: counter(my-awesome-counter) ") ";
        }
      }
    }

    That’s much easier these days with @counter-styles:

    @counter-style parentheses {
      system: extends decimal;
      prefix: "(";
      suffix: ") ";
    }
    CodePen Embed Fallback

    You can style multiple ranges of list items

    Let’s say you have a list of 10 items but you only want to style items 1-3. We can set a range for that:

    @counter-style single-range {
      system: extends upper-roman;
      suffix: ".";
      range: 1 3;
    }
    
    li {
      list-style: single-range;
    }
    CodePen Embed Fallback

    We can even extend our own dice example from earlier:

    Hostinger
    @counter-style dice {
      system: additive;
      additive-symbols: 6 "⚅", 5 "⚄", 4 "⚃", 3 "⚂", 2 "⚁", 1 "⚀";
      suffix: " ";
    }
    
    @counter-style single-range {
      system: extends dice;
      suffix: ".";
      range: 1 3;
    }
    
    li {
      list-style: single-range;
    }
    CodePen Embed Fallback

    Another way to do that is to use the infinite keyword as the first value:

    @counter-style dice {
      system: additive;
      additive-symbols: 6 "⚅", 5 "⚄", 4 "⚃", 3 "⚂", 2 "⚁", 1 "⚀";
      suffix: " ";
    }
    
    @counter-style single-range {
      system: extends dice;
      suffix: ".";
      range: infinite 3;
    }
    
    li {
      list-style: single-range;
    }

    Speaking of infinite, you can set it as the second value and it will count up infinitely for as many list items as you have.

    Maybe you want to style two ranges at a time and include items 6-9. I’m not sure why the heck you’d want to do that but I’m sure you (or your HIPPO) have got good reasons.

    @counter-style dice {
      system: additive;
      additive-symbols: 6 "⚅", 5 "⚄", 4 "⚃", 3 "⚂", 2 "⚁", 1 "⚀";
      suffix: " ";
    }
    
    @counter-style multiple-ranges {
      system: extends dice;
      suffix: ".";
      range: 1 3, 6 9;
    }
    
    li {
      list-style: multiple-ranges;
    }
    CodePen Embed Fallback

    You can add padding around the list markers

    You ever run into a situation where your list markers are unevenly aligned? That usually happens when going from, say, a single digit to a double-digit. You can pad the marker with extra characters to line things up.

    /* adds leading zeroes to list item markers */
    @counter-style zero-padded-example {
      system: extends decimal;
      pad: 3 "0";
    }

    Now the markers will always be aligned… well, up to 999 items.

    CodePen Embed Fallback

    That’s it!

    I just thought those were some pretty interesting ways to work with list markers in CSS that run counter (get it?!) to how I’ve traditionally approached this sort of thing. And with @counter-style becoming Baseline “newly available” in September 2023, it’s well-supported in browsers.


    Some Things You Might Not Know About Custom Counter Styles originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleThat’s a wrap: GitHub Innovation Graph in 2024
    Next Article Vivaldi 7.1 Delivers Speed Dial Buffs, New Search Engine

    Related Posts

    News & Updates

    The Alters: Release date, mechanics, and everything else you need to know

    June 2, 2025
    News & Updates

    I’ve fallen hard for Starsand Island, a promising anime-style life sim bringing Ghibli vibes to Xbox and PC later this year

    June 2, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    Dispel Appoints Dean Macris as Chief Information Security Officer

    Development

    Bill Gates says Gen Z should worry about 4 “very scary things,” including “keeping control of AI” — after predicting its replacement of humans for most tasks

    News & Updates

    Next-Generation Mobility Solutions with Agentic AI and MongoDB Atlas

    Databases

    CVE-2025-4729 – TOTOLINK A3002R/A3002RU Command Injection Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    Highlights

    Classic Outlook for Windows gets smarter with enhanced meeting scheduling

    April 10, 2025

    Microsoft has introduced a new feature in Classic Outlook for Windows, designed to streamline the…

    CVE-2025-46744 – Apache Struts Username Manipulation

    May 12, 2025

    Precision home robots learn with real-to-sim-to-real

    July 31, 2024

    Can I play Kingdom Come: Deliverance II on ASUS ROG Ally, Steam Deck, and other gaming handhelds?

    February 3, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.