The counter-reset
CSS property resets a CSS counter to a given value. This property will create a new counter or reversed counter with the given name on the specified element.
Normal counters have a default initial value of 0. Reversed counters are intended to count down, and have a default initial value set to the number of elements at the current level. The default initial values make it easy to implement the two most common numbering patterns: counting up from one to the number of elements, and counting down from the number of elements to one.
A counter's value is increased or decreased using the counter-increment
CSS property, and the value of an existing counter may be set using counter-set
.
Try it
In addition to author-created counters, the property can also reset the list-item
counters used by ordered lists (as created using <ol>
elements). These have the same behavior as author-created counters, except they are automatically incremented/decremented by one with each list element. This behavior can be overridden using counter-increment
.
Syntax
counter-reset: my-counter;
counter-reset: my-counter -3;
counter-reset: reversed(my-counter);
counter-reset: reversed(my-counter) -1;
counter-reset: reversed(counter1) 1 counter2 9 reversed(counter3) 4;
counter-reset: none;
counter-reset: inherit;
counter-reset: initial;
counter-reset: revert;
counter-reset: revert-layer;
counter-reset: unset;
The counter-reset
property is specified as either one of the following:
- A
<custom-ident>
or a reversed(<custom-ident>)
naming the counter, followed optionally by an <integer>
. Note that the reversed()
method is used to create a "reversed" counter. You may specify as many counters and reversed counters to reset as you want, with each counter or counter-number pair separated by a space.
- The keyword value
none
.
The "implicit" counter named list-item
can be used to control the numbering for ordered lists, as created using <ol>
Values
-
<custom-ident>
-
The name of the counter to reset.
-
<integer>
-
The value to reset the counter to on each occurrence of the element. Defaults to 0
if not specified.
-
none
-
No counter reset is to be performed. This can be used to override a counter-reset
defined in a less specific rule.
Examples
The following examples show how to reset the counters, but not how they are incremented, decremented, and displayed.
For more-complete examples see Using CSS Counters.
Resetting named counters
h1 {
counter-reset: chapter section 1 page;
}
Reversing a counter
h1 {
counter-reset: reversed(chapter) reversed(section) 1 page;
}
Specifications
Browser compatibility
|
Desktop |
Mobile |
|
Chrome |
Edge |
Firefox |
Internet Explorer |
Opera |
Safari |
WebView Android |
Chrome Android |
Firefox for Android |
Opera Android |
Safari on IOS |
Samsung Internet |
counter-reset |
2 |
12 |
1 |
8 |
9.2 |
3 |
4.4 |
18 |
25 |
10.1 |
1 |
1.0 |
reset_does_not_affect_siblings |
No |
No |
82 |
No |
No |
No |
No |
No |
82 |
No |
No |
No |
reversed |
No |
No |
96 |
No |
No |
No |
No |
No |
96 |
No |
No |
No |