4.15. Matching HTML elements using selectors
4.15.1. Case-sensitivity
The Selectors specification leaves the case-sensitivity of element names, attribute names, and attribute values to be defined by the host language. [CSS3-SELECTORS]
Selectors defines that ID and class selectors, when matched against elements in documents that are in quirks mode, will be matched in an ASCII case-insensitive manner.
When comparing a CSS element type selector to the names of html elements in HTML documents, the CSS element type selector must first be converted to ASCII lowercase. The same selector when compared to other elements must be compared according to its original case. In both cases, the comparison is case-sensitive.
When comparing the name part of a CSS attribute selector to the names of namespace-less attributes on html elements in HTML documents, the name part of the CSS attribute selector must first be converted to ASCII lowercase. The same selector when compared to other attributes must be compared according to its original case. In both cases, the comparison is case-sensitive.
Attribute selectors on an HTML element in an HTML document must treat the values of attributes with the following names as ASCII case-insensitive, with one exception as noted in §10 Rendering:
acceptaccept-charsetalignalinkaxisbgcolorcharsetcheckedclearcodetypecolorcompactdeclaredeferdirdirectiondisabledenctypefaceframehreflanghttp-equivlanglanguagelinkmediamethodmultiplenohrefnoresizenoshadenowrapreadonlyrelrevrulesscopescrollingselectedshapetargettexttype(except as specified in §10 Rendering)valignvaluetypevlink
All other attribute values and everything else must be treated as entirely case-sensitive for the purposes of selector matching. This includes:
- IDs and classes in no-quirks mode and limited-quirks mode
- the names of elements not in the HTML namespace
- the names of html elements in XML documents
- the names of attributes of elements not in the HTML namespace
- the names of attributes of html elements in XML documents
- the names of attributes that themselves have namespaces
4.15.2. Pseudo-classes
There is only one known native implementation of :dir(ltr) pseudo-class matching (Firefox/Gecko). Therefore this feature should not be relied upon.
There are a number of dynamic selectors that can be used with HTML. This section defines when these selectors match HTML elements. [CSS3-SELECTORS] [CSS-UI-3]
:link:visited-
All
aelements that have anhrefattribute, allareaelements that have anhrefattribute, and alllinkelements that have anhrefattribute, must match one of:linkand:visited.Other specifications might apply more specific rules regarding how these elements are to match these pseudo-classes, to mitigate some privacy concerns that apply with straightforward implementations of this requirement.
:active-
The
:activepseudo-class is defined to match an elementwhile an element is being activated by the user
.To determine whether a particular element is being activated for the purposes of defining the
:activepseudo-class only, an HTML user agent must use the first relevant entry in the following list.- If the element has a descendant that is currently matching the
:activepseudo-class - The element is being activated.
- If the element is the labeled control of a
labelelement that is currently matching :active - The element is being activated.
- If the element is a
buttonelement - If the element is an
inputelement whosetypeattribute is in the submit button, image button, Reset Button, or Button state -
The element is being activated if it is in a formal activation state and it is not disabled.
For example, if the user is using a keyboard to push a
buttonelement by pressing the space bar, the element would match this pseudo-class in between the time that the element received thekeydownevent and the time the element received thekeyupevent. - If the element is a
menuitemelement - The element is being activated if it is in a formal activation state and it does not have a
disabledattribute. - If the element is an
aelement that has anhrefattribute - If the element is an
areaelement that has anhrefattribute - If the element is a
linkelement that has anhrefattribute - If the element has its tabindex focus flag set
- The element is being activated if it is in a formal activation state.
- If the element is being actively pointed at
- The element is being activated.
An element is said to be in a formal activation state between the time the user begins to indicate an intent to trigger the element’s activation behavior and either the time the user stops indicating an intent to trigger the element’s activation behavior, or the time the element’s activation behavior has finished running, which ever comes first.
An element is said to be being actively pointed at while the user indicates the element using a pointing device while that pointing device is in the "down" state (e.g., for a mouse, between the time the mouse button is pressed and the time it is depressed; for a finger in a multitouch environment, while the finger is touching the display surface).
- If the element has a descendant that is currently matching the
:hover-
The
:hoverpseudo-class is defined to match an elementwhile the user designates an element with a pointing device
. For the purposes of defining the:hoverpseudo-class only, an HTML user agent must consider an element as being one that the user designates if it is:-
An element that the user indicates using a pointing device.
-
An element that has a descendant that the user indicates using a pointing device.
-
An element that is the labeled control of a
labelelement that is currently matching :hover.
Consider in particular a fragment such as:<p> <label for=c> <input id=a> </label> <span id=b> <input id=c> </span> </p>
If the user designates the element with ID "
a" with their pointing device, then thepelement (and all its ancestors not shown in the snippet above), thelabelelement, the element with ID "a", and the element with ID "c" will match the :hover pseudo-class. The element with ID "a" matches it from condition 1, thelabelandpelements match it because of condition 2 (one of their descendants is designated), and the element with ID "c" matches it through condition 3 (itslabelelement matches :hover). However, the element with ID "b" does not match :hover: its descendant is not designated, even though it matches :hover. -
:focus-
For the purposes of the CSS ':focus' pseudo-class, an element has the focus when its top-level browsing context has the system focus, it is not itself a browsing context container, and it is one of the elements listed in the focus chain of the currently focused area of the top-level browsing context.
:enabled-
The
:enabledpseudo-class must match any element that is one of the following:- a
buttonelement that is not disabled - an
inputelement that is not disabled - a
selectelement that is not disabled - a
textareaelement that is not disabled - an
optgroupelement that does not have adisabledattribute - an
optionelement that is not disabled - a
menuitemelement that does not have adisabledattribute - a
fieldsetelement that is not a disabled fieldset
- a
:disabled-
The
:disabledpseudo-class must match any element that is actually disabled. :checked-
The
:checkedpseudo-class must match any element falling into one of the following categories:inputelements whosetypeattribute is in the Checkbox state and whose checkedness state is trueinputelements whosetypeattribute is in the Radio Button state and whose checkedness state is trueoptionelements whose selectedness is truemenuitemelements whosetypeattribute is in the Checkbox state and that have acheckedattributemenuitemelements whosetypeattribute is in the Radio state and that have acheckedattribute
:indeterminate-
The
:indeterminatepseudo-class must match any element falling into one of the following categories:inputelements whosetypeattribute is in the Checkbox state and whoseindeterminateIDL attribute is set to trueinputelements whosetypeattribute is in the Radio Button state and whose radio button group contains noinputelements whose checkedness state is true.progresselements with novaluecontent attribute
:default-
The
:defaultpseudo-class must match any element falling into one of the following categories:buttonelements that are their form’s default buttoninputelements whosetypeattribute is in the submit button or image button state, and that are their form’s default buttoninputelements to which thecheckedattribute applies and that have acheckedattributeoptionelements that have aselectedattribute
:valid-
The
:validpseudo-class must match any element falling into one of the following categories:- elements that are candidates for constraint validation and that satisfy their constraints
formelements that are not the form owner of any elements that themselves are candidates for constraint validation but do not satisfy their constraintsfieldsetelements that have no descendant elements that themselves are candidates for constraint validation but do not satisfy their constraints
:invalid-
The
:invalidpseudo-class must match any element falling into one of the following categories:- elements that are candidates for constraint validation but that do not satisfy their constraints
formelements that are the form owner of one or more elements that themselves are candidates for constraint validation but do not satisfy their constraintsfieldsetelements that have of one or more descendant elements that themselves are candidates for constraint validation but do not satisfy their constraints
:in-range-
The
:in-rangepseudo-class must match all elements that are candidates for constraint validation, have range limitations, and that are neither suffering from an underflow nor suffering from an overflow. :out-of-range-
The
:out-of-rangepseudo-class must match all elements that are candidates for constraint validation, have range limitations, and that are either suffering from an underflow or suffering from an overflow. :required-
The
:requiredpseudo-class must match any element falling into one of the following categories: :optional-
The
:optionalpseudo-class must match any element falling into one of the following categories: :read-only:read-write-
The
:read-writepseudo-class must match any element falling into one of the following categories, which for the purposes of Selectors are thus considered user-alterable: [CSS3-SELECTORS]inputelements to which thereadonlyattribute applies, and that are mutable (i.e., that do not have thereadonlyattribute specified and that are not disabled)textareaelements that do not have areadonlyattribute, and that are not disabled- elements that are editing hosts or editable and are neither
inputelements nortextareaelements
The
:read-onlypseudo-class must match all other html elements. :dir(ltr)-
The
:dir(ltr)pseudo-class must match all elements whose directionality is 'ltr'. :dir(rtl)-
The
:dir(rtl)pseudo-class must match all elements whose directionality is 'rtl'.
Another section of this specification defines the target element used with the :target pseudo-class.
This specification does not define when an element matches the :lang() dynamic
pseudo-class, as it is defined in sufficient detail in a language-agnostic fashion in the
Selectors specification. [CSS3-SELECTORS]