CSS selector
A pattern, such as .card, #menu or nav a, that picks which elements a CSS rule applies to or which elements a DOM query returns.
In more detail
Selectors can match by tag, class, ID, attribute, position and state, and combine these. The same syntax drives stylesheets and methods such as querySelector, matches and closest.
Related terms
- specificity — The weight the browser gives a CSS selector, used to decide which rule wins when two set the same property.
- pseudo-class — A selector keyword starting with a colon, such as :hover, :checked or :has(), that matches elements by state or relationship rather than by name.
- querySelector() — The DOM method that returns the first element matching a CSS selector, or null if nothing matches.
Taught in
- Modern DOM Querying: querySelector, closest And matches — Frontend Architecture & Web Platform
- The Cascade Algorithm: Specificity, Inheritance And Source Order — Frontend Architecture & Web Platform
- Modern Selectors: :has(), :is(), :where() And Nesting Standards — Frontend Architecture & Web Platform