CSS Reference ยท Lists, Tables and Generated Content
The counter-increment property
Reference for the CSS counter-increment property: raise or lower a named counter each time an element appears, with live examples of nested numbering.
The counter-increment property adds a number to a named counter each time the element it is set on is rendered. Combined with counter-reset and content, it numbers headings, figures, table rows or anything else, with no markup changes.
CSS
figure { counter-increment: fig; } figcaption::before { content: "Figure " counter(fig) ": "; }
Try it
Each h2 increments chapter and resets part, so the sub-numbers restart. The last heading adds 5 at once.
Syntax
CSS
counter-increment: none | [ <counter-name> <integer>? ]+;
| Initial value | none |
| Applies to | All elements |
| Inherited | No |
| Animatable | No |
| Computed value | none, or a list of name and integer pairs |
Values
| Value | Description |
|---|---|
none |
No counter is changed. |
<counter-name> |
The counter to change. If no counter with that name is in scope, one is created first (starting at 0). |
<integer> |
The amount to add; defaults to 1. Negative numbers count down, and 0 leaves the value unchanged. |
Usage notes
- It does not display anything. Print the value with
counter()(orcounters()) incontent, usually on::before. - Increment first, display after. An element's own increment happens before its
::beforeis generated, so the first heading shows1when the counter started at0. - Missing reset. If you forget
counter-reset, the counter is created automatically on the element that increments it, starting at 0, and its scope is that element, its descendants and its following siblings. Numbering outside that scope can then look wrong. Reset it explicitly. display: noneskips. Hidden elements do not count; usevisibility: hiddento keep the numbering.- Multiple counters.
counter-increment: a 2 b -1;changes two counters at once. - Same property, one declaration. A later
counter-incrementrule replaces the whole value, so list all counters together.
Browser support
Supported in all browsers.