---
source: https://iinventedlight.com/library/notes/css-selectors.md
title: "CSS selectors: find the elements a rule should style"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "CC-BY-4.0 (web.dev); CC-BY-4.0 (Chrome Developers); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: web.dev, Selectors; Chrome Developers, More control over :nth-child() selections with the of S syntax. CC-BY-4.0 (https://web.dev/learn/css/flexbox). Copyright Google LLC. web.dev text is CC BY 4.0. CC-BY-4.0 (https://developers.google.com/site-policies). Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License. Copyright Google LLC."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-23
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-23
as_of: 2026-11-23
confidence: medium
untested: "Not reproduced (2026-11-23). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-web: css-selectors"
tags: [css, selectors, nth-child, web]
client: Librarian
sources:
  - id: S1
    title: "Selectors"
    publisher: web.dev
    url: https://web.dev/learn/css/selectors
    accessed: 2026-11-23
    license: "CC-BY-4.0"
  - id: S2
    title: "More control over :nth-child() selections with the of S syntax"
    publisher: Chrome Developers
    url: https://developer.chrome.com/docs/css-ui/css-nth-child-of-s
    accessed: 2026-11-23
    license: "CC-BY-4.0"
---
# CSS selectors: find the elements a rule should style
**Answer:** A CSS selector finds the elements a rule should style. A type selector, a class selector, and an ID selector each match an element in their own way. :nth-child() can select elements in the DOM by their index, and of S can pre-filter a set of child elements first.

## Type, class, and ID

You use a CSS selector to find a specific element and apply a CSS rule.

Type selectors match an HTML element by its tag name, such as section.

Class selectors match any element that lists that name in its class attribute.

An HTML element with an id attribute should be unique on a page. Only one element should have that ID value.

## Selecting by index with :nth-child()

Elements can be chosen from the DOM by their index with the :nth-child() pseudo-class.

The An+B microsyntax gives fine control over which elements you want to select.

If you pass of S, An+B then runs only on children that already match that selector list.

Pre-filter a set of child elements before applying An+B logic on it.

## See also

- [css-specificity](https://iinventedlight.com/library/notes/css-specificity/)
- [css-cascade](https://iinventedlight.com/library/notes/css-cascade/)
- [css-has-selector](https://iinventedlight.com/library/notes/css-has-selector/)

## Claims

- id: C1
  claim: A CSS selector finds a specific element so a rule can style it.
  source: S1
  evidence: "You use a CSS selector to find that specific element"

- id: C2
  claim: A type selector matches an HTML element directly.
  source: S1
  evidence: "A type selector matches a HTML element directly."

- id: C3
  claim: :nth-child() can select elements in the DOM by their index.
  source: S2
  evidence: "select Elements in the DOM by their index"

- id: C4
  claim: The of S syntax pre-filters children before An+B logic runs.
  source: S2
  evidence: "Pre-filter a set of child elements before applying An+B logic"

## Sources

- [S1] Selectors. web.dev. https://web.dev/learn/css/selectors . License: CC-BY-4.0. Accessed 2026-11-23.

- [S2] More control over :nth-child() selections with the of S syntax. Chrome Developers. https://developer.chrome.com/docs/css-ui/css-nth-child-of-s . License: CC-BY-4.0. Accessed 2026-11-23.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: web.dev, Selectors; Chrome Developers, More control over :nth-child() selections with the of S syntax. CC-BY-4.0 (https://web.dev/learn/css/flexbox). Copyright Google LLC. web.dev text is CC BY 4.0. CC-BY-4.0 (https://developers.google.com/site-policies). Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License. Copyright Google LLC. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
