CSS counter-reset property
Example
A method for numbering sections and subsections (such as "Section 1", "1.1", "1.2"):
body
{
counter-reset:
section
;
}
h1
{
counter-reset:
subsection
;
}
h1
:before
{
counter-increment:
section
;
content:
"
Section
"
counter
(
section
) ". "
;
}
h2
:before
{
counter-increment:
subsection
;
content:
counter
(
section
) "."
counter
(
subsection
) " "
;
}
Try it »
Property definition and usage
The counter-reset property creates or resets one or more counters.
The counter-reset property is usually used together with the counter-increment and content properties.
| Default value: | none |
|---|---|
| Inherited: | no |
| Version: | CSS2 |
| JavaScript syntax: | object.style.counterReset="subsection" |
Browser support





All major browsers support the counter-reset property.
Note: IE8 supports the counter-reset property only when a !DOCTYPE is specified.
Attribute values
| Value | Description |
|---|---|
| none | Default. The counter of the selector cannot be reset |
| id number | id defines the selector, id, or class whose counter is reset. number sets the counter value for the number of times this selector appears. It can be positive, zero, or negative. |
| inherit | Specifies that the value of the counter-reset property should be inherited from the parent element |
Related Articles
CSS reference: :before pseudo-element
CSS reference: :after pseudo-element
CSS reference: The content attribute
CSS reference: counter-increment property