counter-reset

counter-reset creates and initializes a named CSS counter. Despite its name, it creates a counter scope; counter-set updates an existing counter instead.

Start a decorative section counter

Each paragraph increments the counter before its pseudo-element displays it. The initial zero produces visible values 1 and 2.

counter-reset comparisonLink

HTML and CSS

HTML

<div class="group">
  <p>Read the HTML.</p>
  <p>Inspect the CSS.</p>
</div>

CSS

.group {
  counter-reset: demo 0;
}
.group p {
  counter-increment: demo;
}
.group p::before {
  content: "Demo " counter(demo) ": ";
  color: #1d4ed8;
}

Edit HTML or CSS to update the preview as you type. Copy code snippet copies the selected tab. Preview spacing and font defaults are not included.

Restart the sequence in separate containers

Each group creates its own counter. Both start at 10 and increment before display, so each displays 11 as its first value.

counter-reset practical exampleLink

HTML and CSS

HTML

<div class="group"><p>First independent group.</p></div>
<div class="group"><p>Second independent group.</p></div>

CSS

.group {
  counter-reset: demo 10;
  border: 1px solid #94a3b8;
  padding-inline: 0.75rem;
  margin-block: 0.5rem;
}
.group p {
  counter-increment: demo;
}
.group p::before {
  content: counter(demo) " — ";
}

Edit HTML or CSS to update the preview as you type. Copy code snippet copies the selected tab. Preview spacing and font defaults are not included.

Values and defaults

The initial value is none and the property is not inherited. Use counter names optionally followed by integer starting values; omitted values for ordinary counters start at zero. Multiple name/value pairs are space-separated. Negative starting values are allowed. Reversed counters use reversed(name), which has separate support and initialization behavior.

Common mistakes

Resetting on every item creates a new counter repeatedly, so the displayed number may never advance as intended. Counter scopes follow document/formatting structure, not a global JavaScript variable. Display:none boxes do not participate normally. Essential numbering is more dependable in an HTML ol; these counters are supplemental demonstration labels, not real footnote references.

Learn counter-increment, counter-set, and ol.

Sources and browser support

MDN: counter-reset describes the syntax and links to the specification and compatibility data. Check individual values in that table when supporting older browsers.