--- id: css-counters title: "CSS Counters" category: "Frontend" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["CSS counters", "counter-reset", "counter-increment", "automatic numbering", "counter() function"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.89 created_at: 2026-06-23 updated_at: 2026-06-23 review_reason: "" merge_history: [] tags: ["css", "web", "frontend", "w3schools", "counters", "generated-content"] raw_sources: ["https://www.w3schools.com/css/css_counters.asp"] applied_in: [] github_commit: "" --- # [[CSS Counters]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) CSS counters are "variables" maintained by CSS whose values can be incremented (or decremented) by CSS rules, enabling automatic numbering of elements like section headings β€” no JavaScript required. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **What counters are** β€” CSS counters are "variables" maintained by CSS, and their values can be incremented (or decremented) by CSS rules. [S1] - **`counter-reset`** β€” creates or resets a counter. [S1] - **`counter-increment`** β€” increments (or decrements) a counter value. [S1] - **`content`** β€” inserts generated content (used with `::before`/`::after`). [S1] - **`counter()`** β€” adds/returns the value of a named counter to an element. [S1] - **Increment direction & amount** β€” `counter-increment` takes a second parameter (default 1); a negative value decrements, and any value can be used to step by more than 1. [S1] ## 🧩 μΆ”μΆœλœ νŒ¨ν„΄ (Extracted patterns) - **Reset on container, increment on item** β€” set `counter-reset` on a container (e.g., `body`) and `counter-increment` on the repeated element's `::before`. [S1] - **Compose generated labels** β€” combine string literals with `counter(name)` inside `content` to produce labels like `"Section 1: "`. [S1] - **Tune the step** β€” change numbering direction/granularity purely by the second argument of `counter-increment` (e.g., `-1`, `2`). [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) **CSS Automatic Numbering With Counters** CSS counters are "variables" maintained by CSS, and their values can be incremented (or decremented) by CSS rules. The properties/functions used are: `counter-reset` (creates or resets a counter), `counter-increment` (increments/decrements a counter value), `content` (inserts generated content), and `counter()` (adds the value of a counter to an element). [S1] **CSS Increase and Decrease Counter** The following example creates a counter for the page (in the `body` selector), then increments the counter value by 1 for each `

` element, adding `"Section : "` before each `

`: [S1] ```css body { counter-reset: section; } h2::before { counter-increment: section; content: "Section " counter(section) ": "; } ``` **Decrementing a Counter** The `counter-increment` property has a second parameter. The default value is 1. To decrease the counter value, you can set it to -1: [S1] ```css body { counter-reset: section; } h2::before { counter-increment: section -1; content: "Section " counter(section) ": "; } ``` **Incrementing by Custom Values** You can increment the counter by any value. Here we increment by 2: [S1] ```css body { counter-reset: section; } h2::before { counter-increment: section 2; content: "Section " counter(section) ": "; } ``` ## πŸ› οΈ 적용 사둀 (Applied in summary) The page's examples are the applied cases: numbering `

` headings as "Section 1:", "Section 2:", etc., plus variants that decrement (`-1`) and step by 2. No external project/commit applications found in the source. ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Basic auto-numbering (language: CSS): ```css body { counter-reset: section; } h2::before { counter-increment: section; content: "Section " counter(section) ": "; } ``` Custom step (language: CSS): ```css h2::before { counter-increment: section 2; } ``` ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) No contradictions found in the source. ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual (μ‹€μ œ 적용 사둀 발견 μ‹œ applied/validated둜 승격 κ°€λŠ₯) - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.89 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[CSS Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[CSS Nested Counters]], [[CSS Pseudo-elements]], [[CSS Lists]] - **μ°Έμ‘° λ§₯락:** Referenced when generating automatic numbering for headings, lists, or sections without scripting. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” CSS Counters β€” https://www.w3schools.com/css/css_counters.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-06-23: Initial draft synthesized from the W3Schools "CSS Counters" page (Astra wiki-curation, P-Reinforce v3.1 format).