2 Selectors Overview
2. Selectors Overview
This section is non-normative, as it merely summarizes the following sections.
A selector represents a structure. This structure can be used as a condition (e.g. in a CSS rule) that determines which elements a selector matches in the document tree, or as a flat description of the HTML or XML fragment corresponding to that structure.
Selectors may range from simple element names to rich contextual representations.
The following table summarizes the Selector syntax:
Pattern
Represents
Section
Level
*
any element
§ 5.2 Universal selector
2
E
an element of type E
§ 5.1 Type (tag name) selector
1
E:not(s1, s2, …)
an E element that does not match either compound selector s1 or compound selector s2
§ 4.3 The Negation (Matches-None) Pseudo-class: :not()
3/4
E:is(s1, s2, …)
an E element that matches compound selector s1 and/or compound selector s2
§ 4.2 The Matches-Any Pseudo-class: :is()
4
E:where(s1, s2, …)
an E element that matches compound selector s1 and/or compound selector s2 but contributes no specificity.
§ 4.4 The Specificity-adjustment Pseudo-class: :where()
4
E:has(rs1, rs2, …)
an E element, if there exists an element that matches either of the relative selectors rs1 or rs2, when evaluated with E as the anchor elements
§ 4.5 The Relational Pseudo-class: :has()
4
E.warning
an E element belonging to the class warning (the document language specifies how class is determined).
§ 6.6 Class selectors
1
E#myid
an E element with ID equal to myid.
§ 6.7 ID selectors
1
E[foo]
an E element with a foo attribute
§ 6.1 Attribute presence and value selectors
2
E[foo="bar"]
an E element whose foo attribute value is exactly equal to bar
§ 6.1 Attribute presence and value selectors
2
E[foo="bar" i]
an E element whose foo attribute value is exactly equal to any (ASCII-range) case-permutation of bar
§ 6.3 Case-sensitivity
4
E[foo="bar" s]
an E element whose foo attribute value is identical to bar
§ 6.3 Case-sensitivity
4
E[foo~="bar"]
an E element whose foo attribute value is a list of whitespace-separated values, one of which is exactly equal to bar
§ 6.1 Attribute presence and value selectors
2
E[foo^="bar"]
an E element whose foo attribute value begins exactly with the string bar
§ 6.2 Substring matching attribute selectors
3
E[foo$="bar"]
an E element whose foo attribute value ends exactly with the string bar
§ 6.2 Substring matching attribute selectors
3
E[foo*="bar"]
an E element whose foo attribute value contains the substring bar
§ 6.2 Substring matching attribute selectors
3
E[foo|="en"]
an E element whose foo attribute value is a hyphen-separated list of values beginning with en
§ 6.1 Attribute presence and value selectors
2
E:dir(ltr)
an element of type E with left-to-right directionality (the document language specifies how directionality is determined)
§ 7.1 The Directionality Pseudo-class: :dir()
4
E:lang(sr, "*-Cyrl")
an element of type E tagged as being in Serbian, (which typically uses Cyrillic, but can be written with Latin characters) but also anything written with Cyrillic characters
§ 7.2 The Language Pseudo-class: :lang()
2/4
E:any-link
an E element being the source anchor of a hyperlink
§ 8.1 The Hyperlink Pseudo-class: :any-link
4
E:link
an E element being the source anchor of a hyperlink of which the target is not yet visited
§ 8.2 The Link History Pseudo-classes: :link and :visited
1
E:visited
an E element being the source anchor of a hyperlink of which the target is already visited
§ 8.2 The Link History Pseudo-classes: :link and :visited
1
E:target
an E element being the target of the current URL
§ 8.3 The Target Pseudo-class: :target
3
E:scope
an E element being a scoping root
§ 8.4 The Reference Element Pseudo-class: :scope
4
E:active
an E element that is in an activated state
§ 9.2 The Activation Pseudo-class: :active
1
E:hover
an E element that is under the cursor, or that has a descendant under the cursor
§ 9.1 The Pointer Hover Pseudo-class: :hover
2
E:focus
an E element that has user input focus
§ 9.3 The Input Focus Pseudo-class: :focus
2
E:focus-within
an E element that has user input focus or contains an element that has input focus.
§ 9.5 The Focus Container Pseudo-class: :focus-within
4
E:focus-visible
an E element that has user input focus, and the UA has determined that a focus ring or other indicator should be drawn for that element
§ 9.4 The Focus-Indicated Pseudo-class: :focus-visible
4
E:enabledE:disabled
a user interface element E that is enabled or disabled, respectively
§ 12.1.1 The :enabled and :disabled Pseudo-classes
3
E:read-writeE:read-only
a user interface element E that is user alterable, or not
§ 12.1.2 The Mutability Pseudo-classes: :read-only and :read-write
3-UI/4
E:placeholder-shown
an input control currently showing placeholder text
§ 12.1.3 The Placeholder-shown Pseudo-class: :placeholder-shown
3-UI/4
E:default
a user interface element E that is the default item in a group of related choices
§ 12.1.5 The Default-option Pseudo-class: :default
3-UI/4
E:checkedE:uncheckedE:indeterminate
a user interface element E that is checked/selected (for instance a radio-button or checkbox), unchecked, or in an indeterminate state (neither checked nor unchecked)
§ 12.2 Input Value States
3
E:validE:invalid
a user-input element E that meets, or doesn’t, its data validity semantics
§ 12.3.1 The Validity Pseudo-classes: :valid and :invalid
3-UI/4
E:in-rangeE:out-of-range
a user-input element E whose value is in-range/out-of-range
§ 12.3.2 The Range Pseudo-classes: :in-range and :out-of-range
3-UI/4
E:requiredE:optional
a user-input element E that requires/does not require input
§ 12.3.3 The Optionality Pseudo-classes: :required and :optional
3-UI/4
E:user-invalid
a user-altered user-input element E with incorrect input (invalid, out-of-range, omitted-but-required)
§ 12.3.4 The User-interaction Pseudo-classes: :user-valid and :user-invalid
4
E:root
an E element, root of the document
§ 13.1 :root pseudo-class
3
E:empty
an E element that has no children (neither elements nor text) except perhaps white space
§ 13.2 :empty pseudo-class
3
E:nth-child(n [of S]?)
an E element, the n-th child of its parent matching S
§ 13.3.1 :nth-child() pseudo-class
3/4
E:nth-last-child(n [of S]?)
an E element, the n-th child of its parent matching S, counting from the last one
§ 13.3.2 :nth-last-child() pseudo-class
3/4
E:first-child
an E element, first child of its parent
§ 13.3.3 :first-child pseudo-class
2
E:last-child
an E element, last child of its parent
§ 13.3.4 :last-child pseudo-class
3
E:only-child
an E element, only child of its parent
§ 13.3.5 :only-child pseudo-class
3
E:nth-of-type(n)
an E element, the n-th sibling of its type
§ 13.4.1 :nth-of-type() pseudo-class
3
E:nth-last-of-type(n)
an E element, the n-th sibling of its type, counting from the last one
§ 13.4.2 :nth-last-of-type() pseudo-class
3
E:first-of-type
an E element, first sibling of its type
§ 13.4.3 :first-of-type pseudo-class
3
E:last-of-type
an E element, last sibling of its type
§ 13.4.4 :last-of-type pseudo-class
3
E:only-of-type
an E element, only sibling of its type
§ 13.4.5 :only-of-type pseudo-class
3
E F
an F element descendant of an E element
§ 14.1 Descendant combinator ( )
1
E > F
an F element child of an E element
§ 14.2 Child combinator (>)
2
E + F
an F element immediately preceded by an E element
§ 14.3 Next-sibling combinator (+)
2
E ~ F
an F element preceded by an E element
§ 14.4 Subsequent-sibling combinator (~)
3
Note: Some Level 4 selectors (noted above as "3-UI") were introduced in [CSS3UI].