Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

counter-set — assigning a counter value

The counter-set property assigns a specific value to a CSS counter, allowing numbering to change without creating a new nested counter.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

counter-set: none | [ <counter-name> <integer>? ]+;

counter-set assigns a value to an existing counter; if none exists, it creates one. In contrast, counter-reset creates a new counter, while counter-increment adds to the current value.

Supply a name and an optional integer, defaulting to 0; negative values are allowed. Separate multiple pairs with spaces. The initial none sets no counters—it does not zero them.

The property is not inherited, although counter state propagates through the document tree. On the same element, counter-set runs after counter-increment, regardless of declaration order. Display the value using counter() in content.

The example produces 1, 7, 8: assignment replaces the earlier increment. An element with display: none does not change the counter.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>counter-set</title>
<style>
  .sequence { counter-reset: step; }
  .sequence p { counter-increment: step; }
  .sequence .jump { counter-set: step 7; }
  .sequence p::before { content: counter(step) ". "; }
</style>
<div class="sequence">
  <p>A</p>
  <p class="jump">B</p>
  <p>C</p>
</div>
</html>

Result

1. A
7. B
8. C

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources