Counters (CSS)
The counter-reset and counter-increment CSS properties and the counter() and counters() functions automatically number headings or ordered list items.
Overview
The counter-reset and counter-increment CSS properties and the counter() and counters() functions automatically number headings or ordered list items.
Browser support
| Feature | Desktop | Mobile | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
| 2 | 12 | 1 | 3 | 18 | 1 | |
list-item | 28 | 12 | 1 | 9 | 28 | 9 |
none | 2 | 12 | 1 | 3 | 18 | 2 |
| Other | ||||||
| The counter-reset CSS property creates named CSS counters and initializes them to a specific value. It supports creating counters that count up from one to the number of elements, as well as those that count down from the number of elements to one. | 2 | 12 | 1 | 3 | 18 | 1 |
| CSS property | ||||||
list-item | 28 | 12 | 1 | 9 | 28 | 9 |
none | 2 | 12 | 1 | 3 | 18 | 2 |
reset does not affect siblings Experimental Resets counter on current element (not sibling elements). | | | 82 | | | |
| Other | ||||||
| The counter() CSS function returns a string representing the current value of the named counter, if there is one. | 1 | 12 | 1 | 3 | 18 | 1 |
| The counters() CSS function enables combining markers when nesting counters. The function returns a string that concatenates the current values of the named and nested counters, if any are present, with the string provided. The third, optional parameter enables defining the list style. | 1 | 12 | 1.5 | 3 | 18 | 1 |
- This browser only partially implements this feature
- Overriding the initial value of the implicit `list-item` counter has no effect when the default marker string for list items (`::marker`) is generated; see bug 338233131.
- This browser only partially implements this feature
- Overriding the initial value of the implicit `list-item` counter results in incorrect values for the `counter()` function used to generate content, as it is not fully implemented; see bug 260436.
- This browser only partially implements this feature
- Overriding the initial value of the implicit `list-item` counter has no effect when the default marker string for list items (`::marker`) is generated; see bug 338233131.
- This browser only partially implements this feature
- Overriding the initial value of the implicit `list-item` counter results in incorrect values for the `counter()` function used to generate content, as it is not fully implemented; see bug 260436.
Syntax
body {
counter-reset: chapter;
}
h2::before {
counter-increment: chapter;
content: 'Chapter ' + counter(chapter);
} Live demo
Use cases
Using Counters (CSS)
The counter-reset and counter-increment CSS properties and the counter() and counters() functions automatically number headings or ordered list items.
Cautions
- May not be supported in older browsers.
Accessibility
- Make sure visual changes are conveyed appropriately to assistive technology.
Related links
Powered by web-features