--- 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 `
  1. ::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 `
    1. `, 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).