@counter-style

Term side of the Card.
Topic: Directives
Unit title: @counter-style
Categories: Directive
Explanation side of the Card

Explanation: The directive that defines custom counter styles, such as the appearance of list item markers. It allows creating unique bullet points, numbers or symbols for ordered and unordered lists, enhancing list presentation.

Browser compatibility:
  • The chrome browser supports this feature starting from version 91.
  • The edge browser supports this feature starting from version 91.
  • The firefox browser supports this feature starting from version 33.
  • The safari browser supports this feature starting from version 17.
Availability: 

Example

Wrongcss
li::before {
  content: "★ ";
}
Rightcss
@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-style without defining it, so the default shows.
  • Forgetting suffix, so markers have no space before the text.

Key points

  • The rule sets system and symbols, with a fallback for 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?

Yes, pass the name as the second argument: counter(step, stars).

Analytics cookiesWe'd like to use analytics cookies to see which pages are useful. They're set only if you accept. Privacy Policy