counter-set

Term side of the Card.
Topic: Counters
Unit title: counter-set
Categories: Property
Explanation side of the Card

Explanation: The property that directly sets the value of a counter to a specific number, overriding any previous value. This provides precise control over the counter's value, useful for custom numbering or complex layouts.

Browser compatibility:
  • The chrome browser supports this feature starting from version 85.
  • The edge browser supports this feature starting from version 85.
  • The firefox browser supports this feature starting from version 68.
  • The safari browser supports this feature starting from version 17.2.
Availability: 

Example

Wrongcss
li {
  counter-increment: item;
}
li.jump {
  counter-reset: item 10;
}
Rightcss
li {
  counter-increment: item;
}
li.jump {
  counter-set: item 10;
}

counter-set runs after the increment and reuses the existing counter, so this item shows 10 instead of 11.

Common mistakes

  • Using counter-reset on a middle item, which creates a new counter and shows one more than expected.

Key points

  • Jumps in numbering use counter-set, while counter-reset stays on the container that starts the counter.
  • The set value is the number to show, since counter-set applies after counter-increment.

Interview questions

What is the difference between counter-set and counter-reset?

counter-reset creates a new counter scope. counter-set only changes the value of a counter that already exists.

Can I set an ordered list item number without CSS?

Yes. The value attribute on <li> sets the number of that item in an <ol>.

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