← Back to functions

CSS Function

counter()

Content

Returns the current value of a named CSS counter.

Syntax

counter(name, style?)

Example

content: counter(section, upper-roman);

Common use cases

  • Custom numbered lists
  • Automatic heading numbering
  • Nested list counters

Practical developer insight

Pair counter() with counter-reset and counter-increment on parent elements. Use counters() (plural) for nested formats like chapter.subsection.

Related