--- id: css-selectors title: "CSS Selectors" category: "Frontend" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["CSS selector", "element selector", "id selector", "class selector", "universal selector", "simple selectors"] 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", "selectors"] raw_sources: ["https://www.w3schools.com/css/css_selectors.asp"] applied_in: [] github_commit: "" --- # [[CSS Selectors]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) CSS selectors are used to "find" (select) the HTML elements you want to style, ranging from simple selectors that match by name, id, or class to combinator, pseudo-class, pseudo-element, and attribute selectors. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **Purpose** β€” a CSS selector selects the HTML element(s) you want to style. [S1] - **Five categories** β€” Simple selectors (by name, id, class), Combinator selectors, Pseudo-class selectors, Pseudo-elements selectors, and Attribute selectors. [S1] - **Element selector** β€” selects elements based on the element name (e.g. `p`). [S1] - **id selector** β€” uses the `#` character plus the id of a specific element; an id is unique within a page. [S1] - **class selector** β€” uses a `.` followed by a class name; multiple elements can share a class. [S1] - **Naming rule** β€” an id name cannot start with a number, and a class name cannot start with a number. [S1] ## 🧩 μΆ”μΆœλœ νŒ¨ν„΄ (Extracted patterns) - **By type** β€” `element { ... }` styles all elements of that tag. [S1] - **By id** β€” `#id { ... }` styles the one element with that id. [S1] - **By class** β€” `.class { ... }` styles every element carrying that class. [S1] - **Type + class scoping** β€” `element.class { ... }` styles only those elements of a type that also carry the class. [S1] - **Multiple classes** β€” an element can reference more than one class at once via a space-separated `class` attribute. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) A CSS selector is used to find (select) the HTML elements you want to style. CSS selectors divide into five categories: Simple selectors (select elements based on name, id, class), Combinator selectors, Pseudo-class selectors, Pseudo-elements selectors, and Attribute selectors. [S1] **The CSS element selector** selects HTML elements based on the element name. [S1] ```css p { text-align: center; color: red; } ``` **The CSS id selector** uses the id attribute of an HTML element to select a specific element. The id of an element is unique within a page, so it selects one unique element. To select an element with a specific id, write a hash (`#`) character followed by the id of the element. [S1] ```css #para1 { text-align: center; color: red; } ``` Note: an id name cannot start with a number! [S1] **The CSS class selector** selects HTML elements with a specific class attribute. To select elements with a specific class, write a period (`.`) character followed by the class name. [S1] ```css .center { text-align: center; color: red; } ``` You can also specify that only specific HTML elements should be affected by a class. In this example only `

` elements with `class="center"` will be center-aligned and red: [S1] ```css p.center { text-align: center; color: red; } ``` HTML elements can also refer to more than one class: [S1] ```html

This paragraph refers to two classes.

``` Note: a class name cannot start with a number! [S1] **The CSS universal selector** (`*`) selects all HTML elements on the page. [S1] ```css * { text-align: center; color: blue; } ``` **The CSS grouping selector** selects all the HTML elements with the same style definitions. To group selectors, separate each selector with a comma. [S1] ```css h1, h2, p { text-align: center; color: red; } ``` **All CSS Simple Selectors** [S1] | Selector | Example | Example description | | --- | --- | --- | | `#id` | `#firstname` | Selects the element with id="firstname" | | `.class` | `.intro` | Selects all elements with class="intro" | | `element.class` | `p.intro` | Selects only `

` elements with class="intro" | | `*` | `*` | Selects all elements | | `element` | `p` | Selects all `

` elements | | `element,element,..` | `div, p` | Selects all `

` elements and all `

` elements | ## πŸ› οΈ 적용 사둀 (Applied in summary) The page's own examples apply each selector type to style headings and paragraphs (element, id, class, type+class, universal, and grouping). No external project/commit applications found in the source. ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Selecting by id and by class (language: CSS): ```css #para1 { text-align: center; color: red; } .center { text-align: center; color: red; } ``` Scoping a class to a specific element type: ```css p.center { text-align: center; color: red; } ``` ## βš–οΈ 비ꡐ 및 선택 κΈ°μ€€ (Comparison & decision criteria) | Selector | When to use | Scope | | --- | --- | --- | | `element` (e.g. `p`) | Style every element of a tag uniformly | All elements of that type [S1] | | `#id` (e.g. `#para1`) | Style one unique element | A single element (id is unique per page) [S1] | | `.class` (e.g. `.center`) | Reuse a style across many elements | All elements carrying that class [S1] | | `element.class` (e.g. `p.center`) | Reuse a class but limit it to one tag | Only that element type with the class [S1] | | `*` | Apply a baseline to everything | All elements on the page [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.89 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[CSS Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[CSS Syntax]], [[CSS Grouping Selectors]], [[CSS Introduction]] - **μ°Έμ‘° λ§₯락:** Referenced whenever deciding how to target HTML elements for styling. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” CSS Selectors β€” https://www.w3schools.com/css/css_selectors.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-06-23: Initial draft synthesized from the W3Schools "CSS Selectors" page (Astra wiki-curation, P-Reinforce v3.1 format).