counters() CSS Function
Description
The counters() CSS function is used to return a string representing the value of a series of counters that have been incremented through the document using the counter-increment property. Unlike the counter() function, which retrieves a single counter value, counters() allows you to concatenate multiple counter levels into a single string, separated by a defined delimiter.
This function is especially useful when styling hierarchical elements such as nested ol lists or headings, where you want to display numbering like "1.2.3" to indicate levels of depth. Each counter in the series is defined by its name and can be formatted with a string, such as decimal numbers, Roman numerals, or letters.
For example, consider nested li items where you want each sub-item to show a multi-level numbering:
ol {
counter-reset: section;
}
li {
counter-increment: section;
}
li::before {
content: counters(section, ".") " ";
}
In this example, the counters(section, ".") function concatenates the counter values of all parent li elements in the hierarchy, separated by a period. So, a third-level item could appear as "1.2.3".
You can also combine counters() with other text in the content property to create more descriptive labels:
li::before {
content: "Section " counters(section, ".") ": ";
}
Here, the text "Section" is prepended to the hierarchical numbering, producing output like "Section 2.1: ". This makes counters() a powerful tool for automatically numbering nested content without manually updating each element.
Syntax
counters(<counter-name>, <connector-string> [, <counter-style>])
Values
- <counter-name>(Required): The case-sensitive name of the counter you defined using counter-reset.
- <connector-string>(Required): A string that acts as the separator between the different levels of the counter (e.g., a dot . or a dash -).
- <counter-style>(Optional): Defines the list style (e.g., decimal, lower-roman, upper-alpha). If omitted, it defaults to decimal.
Example
Browser Support
The following information will show you the current browser support for the CSS counters() function. Hover over a browser icon to see the version that first introduced support for this CSS function.
This function is supported by all modern browsers.
Desktop
Tablets & Mobile
Last updated by CSSPortal on: 1st January 2026
