CSS counter-reset Property
Example
body {
/* Set "myCounter" to 0 */
counter-reset: myCounter;
}
h2::before {
/* Increment "myCounter" by 1 */
counter-increment: myCounter;
content: "Section: " counter(myCounter) ". ";
}
Meaning
The counter-reset 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.
Default value: | none |
Inherited: | No |
Animatable: | No |
Version: | CSS2 |
JavaScript syntax: |
|
Standard Syntax
counter-reset: none|name number|initial|inherit|revert|revert-layer|unset;
Browser Support
The numbers in the table specify the first browser version that fully supports the property.
Status
Property Values
The following table describes the values of this property.
Value | Description |
---|---|
none | This is default value. No counters will be reset. |
Id/number | The id defines which counter to reset. The number sets the value the counter is reset to on each occurrence of the selector. The default number value is 0. |
initial | Sets this property to its default value. |
inherit | If specified, the associated element takes the computed value of its parent element animation-delay property. |
revert | Reverts the cascaded value of the property from its current value to the value the property |
revert-layer | Rollback styles to the ones specified in previous cascade layers. |
unset | Resets a property to its inherited value if the property naturally inherits from its parent, and to its initial value if not. |
Default CSS Property Values
selectors {
counter-reset: none;
}
More Examples:
The following example will show how to change counter styles:
Example
body {
counter-reset: chapter;
}
h2::before {
counter-increment: chapter;
content: counter(chapter, upper-roman) ": ";
}
Create counter from 5:
Note: The counter will start from 6.
Example
body {
counter-reset: chapter 5;
}
h2::before {
counter-increment: chapter;
content: "Chapter " counter(chapter) ": ";
}