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

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 31, 2025

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

      May 31, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 31, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 31, 2025

      Windows 11 version 25H2: Everything you need to know about Microsoft’s next OS release

      May 31, 2025

      Elden Ring Nightreign already has a duos Seamless Co-op mod from the creator of the beloved original, and it’ll be “expanded on in the future”

      May 31, 2025

      I love Elden Ring Nightreign’s weirdest boss — he bargains with you, heals you, and throws tantrums if you ruin his meditation

      May 31, 2025

      How to install SteamOS on ROG Ally and Legion Go Windows gaming handhelds

      May 31, 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

      Oracle Fusion new Product Management Landing Page and AI (25B)

      May 31, 2025
      Recent

      Oracle Fusion new Product Management Landing Page and AI (25B)

      May 31, 2025

      Filament Is Now Running Natively on Mobile

      May 31, 2025

      How Remix is shaking things up

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

      Windows 11 version 25H2: Everything you need to know about Microsoft’s next OS release

      May 31, 2025
      Recent

      Windows 11 version 25H2: Everything you need to know about Microsoft’s next OS release

      May 31, 2025

      Elden Ring Nightreign already has a duos Seamless Co-op mod from the creator of the beloved original, and it’ll be “expanded on in the future”

      May 31, 2025

      I love Elden Ring Nightreign’s weirdest boss — he bargains with you, heals you, and throws tantrums if you ruin his meditation

      May 31, 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:

    @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

    Windows 11 version 25H2: Everything you need to know about Microsoft’s next OS release

    May 31, 2025
    News & Updates

    Elden Ring Nightreign already has a duos Seamless Co-op mod from the creator of the beloved original, and it’ll be “expanded on in the future”

    May 31, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    This dual-screen gaming handheld tempts with emulation but wins with simultaneous Cyberpunk 2077 and Netflix

    Development

    20+ Best Free Magazine & News WordPress Themes in 2025

    Learning Resources

    How to use feature flags

    Development

    New Guide Empowers Australian Tech Workers to Expose Corporate Wrongdoings

    News & Updates

    Highlights

    CVE-2025-31235 – “Apple iPadOS and macOS Double Free Vulnerability”

    May 12, 2025

    CVE ID : CVE-2025-31235

    Published : May 12, 2025, 10:15 p.m. | 1 hour, 28 minutes ago

    Description : A double free issue was addressed with improved memory management. This issue is fixed in iPadOS 17.7.7, macOS Ventura 13.7.6, macOS Sequoia 15.5, macOS Sonoma 14.7.6. An app may be able to cause unexpected system termination.

    Severity: 0.0 | NA

    Visit the link for more details, such as CVSS details, affected products, timeline, and more…

    Microsoft is using a long-forgotten Xbox game for a new generative AI experiment

    February 20, 2025

    Celebrating the Visionary Genius of Digital Marketing: Srinidhi Ranganathan and His Musical Masterpiece “I Cannot Live Without YouTube”

    June 18, 2024

    Kingdom Come: Deliverance 2 preorder guide — Bonus, Collector’s Edition, and where to buy

    January 30, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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