counter-set
Example
li {
counter-increment: item;
}
li.jump {
counter-reset: item 10;
}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-reseton a middle item, which creates a new counter and shows one more than expected.
Key points
- Jumps in numbering use
counter-set, whilecounter-resetstays on the container that starts the counter. - The set value is the number to show, since
counter-setapplies aftercounter-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>.