CSS counter-increment
Property
The counter-increment
property in CSS is used to increase the value of a counter in ordered lists, sections, or any repeating elements. It works with the counter-reset
and content
properties to create automatic numbering.
1. Syntax
Value | Description |
---|---|
counter-name | The name of the counter to increment. |
number (optional, default is 1 ) | The amount by which the counter increases. |
✅ Use counter-increment
with content: counter(counter-name);
in ::before
or ::after
pseudo-elements to display numbers.
2. Example – Automatic Numbering for Sections
✅ Outputs:
3. Example – Ordered List with Custom Numbers
✅ Outputs:
4. Example – Custom Counter Increment
✅ Increments by 2 instead of 1.
5. Best Practices
✔ Always reset counters with counter-reset
before using counter-increment
.
✔ Use counter-increment: counter-name 2;
to skip numbers.
✔ Works best with ::before
or ::after
for automatic numbering.