The CSS selectors module defines the patterns to select elements to which a set of CSS rules are then applied along with their specificity. The CSS selectors module provides us with more than 60 selectors and five combinators. Other modules provide additional pseudo-class selectors and pseudo-elements.
In CSS, selectors are patterns used to match, or select, the elements you want to style. Selectors are also used in JavaScript to enable selecting the DOM nodes to return as a NodeList.
Selectors, whether used in CSS or JavaScript, enable targeting HTML elements based on their type, attributes, current states, and even position in the DOM. Combinators allow you to be more precise when selecting elements by enabling selecting elements based on their relationship to other elements.
+ (Next-sibling combinator)> (Child combinator)~ (Subsequent sibling combinator)| (Namespace separator), (Selector list)The CSS selectors module also introduces the column combinator (||). Currently, no browsers support this feature.
:active:any-link:autofill:buffering:checked:default:defined:dir():disabled:empty:enabled:first-child:first-of-type:focus:focus-visible:focus-within:fullscreen:future:has():hover:in-range:indeterminate:invalid:is():lang():last-child:last-of-type:link:matches() (obsolete legacy selector alias for :is()):modal:muted:not():nth-child():nth-of-type():nth-last-child():nth-last-of-type():only-child:only-of-type:open:optional:out-of-range:past:paused:picture-in-picture:placeholder-shown:playing:popover-open:read-only:read-write:required:root:scope:seeking:stalled:target:user-invalid:user-valid:valid:visited:volume-locked:where():-webkit- pseudo-classesThe CSS selectors module also introduces the :blank, :current, and :local-link pseudo-classes. Currently, no browsers support these features.
Overview of the different types of simple selectors and various combinators defined in the CSS selectors and the CSS pseudo modules.
Explanation of the structure of CSS selectors and the terminologies introduced in the CSS selectors module, ranging from "simple selector" to "forgiving relative selector list".
Lists the pseudo-classes, selectors that allow the selection of elements based on state information that is not contained in the document tree, defined in the various CSS modules and HTML.
:target pseudo-class in selectorsLearn how to use the :target pseudo-class to style the target element a URL's fragment identifier.
:visited selectorExplores the style limitations set on the :visited class for user privacy.
Introduction to basic CSS selectors, including tutorials on Type, class, and ID selectors, Attribute selectors, Pseudo-classes and pseudo-elements, and Combinators.
Learn the different UI pseudo-classes available for styling forms in different states.
The selectors API enables using selectors in JavaScript to retrieve element nodes from the DOM.
state() pseudo-class
CSS nesting module
CSS scoping module
:host pseudo-class:host() pseudo-class:host-context() pseudo-class:has-slotted pseudo-class::slotted pseudo-elementCSS overflow module
CSS multi-column layout module
CSS paged media module
CSS pseudo-element module (representing entities not included in HTML)
::part pseudo-elementOther pseudo-elements
@namespace at-rule
!importantDocument.querySelector method
Document.querySelectorAll method
NodeList.forEach() method
| Specification |
|---|
| Selectors Level 4> |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_selectors