CSS counter-increment 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-increment property increases or decreases the value of a CSS counter by a given value.
Note: The counter's value can be reset to an arbitrary number using the counter-reset CSS property.
Default value: | none |
Inherited: | No |
Animatable: | No |
Version: | CSS2 |
JavaScript syntax: |
|
Standard Syntax
counter-increment: none|id|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 incremented. |
id/number | The id defines which counter to increment. The number sets how much the counter will increment on each occurrence of the selector. The default increment is 1. Negative values are allowed. If id refers to a counter that has not been initialized by counter-reset, the default initial 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-increment: 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 jump 5 steps:
Example
body {
counter-reset: chapter;
}
h2::before {
counter-increment: chapter 5;
content: "Chapter " counter(chapter) ": ";
}
Create decreased counter:
Example
body {
counter-reset: chapter;
}
h2::before {
counter-increment: chapter -1;
content: "Chapter " counter(chapter) ": ";
}