A CSS pseudo-class is a keyword added to a selector that specifies a special state of the selected element(s). For example, the pseudo-class
:hover can be used to select a button when a user's pointer hovers over the button and this selected button can then be styled.
/* Any button over which the user's pointer is hovering */
A pseudo-class consists of a colon (
:) followed by the pseudo-class name (e.g.,
:hover). A functional pseudo-class also contains a pair of parentheses to define the arguments (e.g.,
:dir()). The element that a pseudo-class is attached to is defined as an anchor element (e.g.,
button in case
Pseudo-classes let you apply a style to an element not only in relation to the content of the document tree, but also in relation to external factors like the history of the navigator (
:visited, for example), the status of its content (like
:checked on certain form elements), or the position of the mouse (like
:hover, which lets you know if the mouse is over an element or not).
Note: In contrast to pseudo-classes, pseudo-elements can be used to style a specific part of an element.
These pseudo-classes enable the selection of elements based on their display states.
Matches an element that is currently in fullscreen mode.
Matches an element that is in a state in which it excludes all interaction with elements outside it until the interaction has been dismissed.
Matches an element that is currently in picture-in-picture mode.
These pseudo-classes relate to form elements, and enable selecting elements based on HTML attributes and the state that the field is in before and after interaction.
Matches when an
<input>has been autofilled by the browser.
Represents a user interface element that is in an enabled state.
Represents a user interface element that is in a disabled state.
Represents any element that cannot be changed by the user.
Represents any element that is user-editable.
Matches one or more UI elements that are the default among a set of elements.
Matches when elements such as checkboxes and radio buttons are toggled on.
Matches UI elements when they are in an indeterminate state.
Matches a user-input element which is empty, containing an empty string or other null input.
Matches an element with valid contents. For example, an input element with the type 'email' that contains a validly formed email address or an empty value if the control is not required.
Matches an element with invalid contents. For example, an input element with type 'email' with a name entered.
Applies to elements with range limitations. For example, a slider control when the selected value is in the allowed range.
Applies to elements with range limitations. For example, a slider control when the selected value is outside the allowed range.
Matches when a form element is required.
Matches when a form element is optional.
Represents an element with correct input, but only when the user has interacted with it.
Represents an element with incorrect input, but only when the user has interacted with it.
These pseudo-classes reflect the document language and enable the selection of elements based on language or script direction.
These pseudo-classes relate to links, and to targeted elements within the current document.
Matches links that have not yet been visited.
Matches links that have been visited.
Matches links whose absolute URL is the same as the target URL. For example, anchor links to the same page.
Matches the element which is the target of the document URL.
Matches elements which are the target of the document URL, but also elements which have a descendant which is the target of the document URL.
Represents elements that are a reference point for selectors to match against.
These pseudo-classes apply to media that is capable of being in a state where it would be described as playing, such as a video.
These pseudo-classes apply when viewing something which has timing, such as a WebVTT caption track.
These pseudo-classes relate to the location of an element within the document tree.
Represents an element that is the root of the document. In HTML this is usually the
Represents an element with no children other than white-space characters.
An+Bnotation to select elements from a list of sibling elements.
An+Bnotation to select elements from a list of sibling elements, counting backwards from the end of the list.
Matches an element that is the first of its siblings.
Matches an element that is the last of its siblings.
Matches an element that has no siblings. For example, a list item with no other list items in that list.
An+Bnotation to select elements from a list of sibling elements that match a certain type from a list of sibling elements.
An+Bnotation to select elements from a list of sibling elements that match a certain type from a list of sibling elements counting backwards from the end of the list.
Matches an element that is the first of its siblings, and also matches a certain type selector.
Matches an element that is the last of its siblings, and also matches a certain type selector.
Matches an element that has no siblings of the chosen type selector.
These pseudo-classes require some interaction by the user in order for them to apply, such as holding a mouse pointer over an element.
Matches when a user designates an item with a pointing device, such as holding the mouse pointer over the item.
Matches when an item is being activated by the user. For example, when the item is clicked on.
Matches when an element has focus.
Matches when an element has focus and the user agent identifies that the element should be visibly focused.
The matches-any pseudo-class matches any element that matches any of the selectors in the list provided. The list is forgiving.
The negation, or matches-none, pseudo-class represents any element that is not represented by its argument.
The specificity-adjustment pseudo-class matches any element that matches any of the selectors in the list provided without adding any specificity weight. The list is forgiving.
The relational pseudo-class represents an element if any of the relative selectors match when anchored against the attached element.
Like regular classes, you can chain together as many pseudo-classes as you want in a selector.
Pseudo-classes defined by a set of CSS specifications include the following:
|Selectors Level 4
|CSS Basic User Interface Module Level 4