---
id: css-nested-counters
title: "CSS Nested Counters"
category: "Frontend"
status: "draft"
verification_status: "conceptual"
canonical_id: ""
aliases: ["CSS nested counters", "counters() function", "multi-level numbering", "section subsection numbering", "nested list numbering"]
duplicate_of: ""
source_trust_level: "B"
confidence_score: 0.88
created_at: 2026-06-23
updated_at: 2026-06-23
review_reason: ""
merge_history: []
tags: ["css", "web", "frontend", "w3schools", "counters", "generated-content", "lists"]
raw_sources: ["https://www.w3schools.com/css/css_counters_nested.asp"]
applied_in: []
github_commit: ""
---
# [[CSS Nested Counters]]
## π― ν μ€ ν΅μ°° (One-line insight)
By running two counters at once β or by using the `counters()` function β CSS can produce multi-level numbering such as "Section 1.1" or outline-style "1.1.1" labels for nested lists, all without JavaScript. [S1]
## π§ ν΅μ¬ κ°λ
(Core concepts)
- **Two counters** β you can maintain more than one counter to number different levels (e.g., a `section` counter for the page and a `subsection` counter reset on each `
`). [S1]
- **`counters()` function** β returns the current values of the named and nested counters, as a string. [S1]
- **`counters()` vs `counter()`** β `counter()` returns the current value of a single named counter; `counters()` returns the named and nested counter values combined into a string. [S1]
- **Separator argument** β `counters(name, separator)` inserts a string (e.g., `"."`) between nesting levels. [S1]
## π§© μΆμΆλ ν¨ν΄ (Extracted patterns)
- **Per-level reset** β reset the lower-level counter on the higher-level element (reset `subsection` on each ``) so it restarts under every parent. [S1]
- **Self-nesting lists** β reset the same counter on every `` and emit `counters(section,".")` on each `- ::before` to auto-build hierarchical numbers like 1, 1.1, 1.2. [S1]
## π μΈλΆ λ΄μ© (Details)
**CSS Using Two Counters**
You can create multiple counters for different numbering levels: a `section` counter for the page and a `subsection` counter for each `
` element. The `section` counter increments on each ``, while a `subsection` counter (reset on each ``) increments on each ``, producing labels like "Section 1." and "1.1". [S1]
```css
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) " ";
}
```
**The CSS counters() Function**
The `counters()` function returns the current values of the named and nested counters, as a string. In this example, the same `section` counter is reset on every `` and incremented on each `- `, and `counters(section,".")` joins the nested values with a `"."` separator to produce outline numbering within an ordered-list structure: [S1]
```css
ol {
counter-reset: section;
list-style-type: none;
}
li::before {
counter-increment: section;
content: counters(section,".") " ";
}
```
**CSS Counter Properties**
The page lists the following counter-related properties and functions: [S1]
| Property / Function | Description |
| --- | --- |
| `content` | Used with the `::before` and `::after` pseudo-elements, to insert generated content [S1] |
| `counter-increment` | Increments one or more counter values [S1] |
| `counter-reset` | Creates or resets one or more counters [S1] |
| `counter()` | Returns the current value of the named counter [S1] |
| `counters()` | Returns the current values of the named and nested counters [S1] |
## π οΈ μ μ© μ¬λ‘ (Applied in summary)
The page's examples are the applied cases: "Section N." / "N.M" headings produced by two counters, and outline-style "1.1.1" numbering for a nested ordered list via `counters()`. No external project/commit applications found in the source.
## π» μ½λ ν¨ν΄ (Code patterns)
Two-level heading numbering (language: CSS):
```css
h1::before {
counter-increment: section;
content: "Section " counter(section) ". ";
}
h2::before {
counter-increment: subsection;
content: counter(section) "." counter(subsection) " ";
}
```
Self-nesting list numbering (language: CSS):
```css
li::before {
counter-increment: section;
content: counters(section,".") " ";
}
```
## βοΈ λΉκ΅ λ° μ ν κΈ°μ€ (Comparison & decision criteria)
- **`counter()`** β use when you need the value of a single counter at one level (e.g., "Section 3"). [S1]
- **`counters()`** β use when you need the named and nested counter values joined into one string for multi-level/outline numbering (e.g., "3.2.1"), supplying a separator argument such as `"."`. [S1]
## βοΈ λͺ¨μ λ° μ
λ°μ΄νΈ (Contradictions & updates)
No contradictions found in the source.
## β
κ²μ¦ μν λ° μ λ’°λ
- **μν:** draft
- **κ²μ¦ λ¨κ³:** conceptual (μ€μ μ μ© μ¬λ‘ λ°κ²¬ μ applied/validatedλ‘ μΉκ²© κ°λ₯)
- **μΆμ² μ λ’°λ:** B (W3Schools β widely used educational reference, not a primary standards body)
- **μ λ’° μ μ:** 0.88
- **μ€λ³΅ κ²μ¬ κ²°κ³Ό:** μ κ· μμ± (New discovery)
## π μ§μ κ·Έλν (Knowledge Graph)
- **μμ/루νΈ:** [[CSS Tutorial]]
- **κ΄λ ¨ κ°λ
:** [[CSS Counters]], [[CSS Lists]], [[CSS Pseudo-elements]]
- **μ°Έμ‘° λ§₯λ½:** Referenced when building multi-level outline numbering for headings or nested lists.
## π μΆμ² (Sources)
- [S1] W3Schools β CSS Nested Counters β https://www.w3schools.com/css/css_counters_nested.asp
## π λ³κ²½ μ΄λ ₯ (Change history)
- 2026-06-23: Initial draft synthesized from the W3Schools "CSS Nested Counters" page (Astra wiki-curation, P-Reinforce v3.1 format).