@counter-style
Example
li::before {
content: "★ ";
}@counter-style stars {
system: cyclic;
symbols: "★";
suffix: " ";
}
ul {
list-style: stars;
}A counter style keeps the marker in ::marker, so it aligns like a real list bullet.
Common mistakes
- Using a custom style name in
list-stylewithout defining it, so the default shows. - Forgetting
suffix, so markers have no space before the text.
Key points
- The rule sets
systemandsymbols, with afallbackfor unsupported ranges. - Lists keep real
<ol>or<ul>markup, so the counter is semantic.
Interview questions
Can I extend a built-in counter style?
Yes, system: extends decimal reuses an existing style and lets you change prefix or suffix.
Can I use @counter-style with CSS counters?
@counter-style with CSS counters?Yes, pass the name as the second argument: counter(step, stars).