docs.rodeo

MDN Web Docs mirror

Pseudo-classes

{{CSSRef}} 

A CSS pseudo-class is a keyword added to a selector that lets you style a specific state of the selected element(s). For example, the pseudo-class {{CSSxRef(":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 */
button:hover {
  color: blue;
}

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 button:hover).

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 ({{CSSxRef(":visited")}} , for example), the status of its content (like {{CSSxRef(":checked")}}  on certain form elements), or the position of the mouse (like {{CSSxRef(":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.

Element display state pseudo-classes

These pseudo-classes enable the selection of elements based on their display states.

Input pseudo-classes

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.

Linguistic pseudo-classes

These pseudo-classes reflect the document language and enable the selection of elements based on language or script direction.

Location pseudo-classes

These pseudo-classes relate to links, and to targeted elements within the current document.

Resource state pseudo-classes

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.

Time-dimensional pseudo-classes

These pseudo-classes apply when viewing something which has timing, such as a WebVTT caption track.

Tree-structural pseudo-classes

These pseudo-classes relate to the location of an element within the document tree.

User action pseudo-classes

These pseudo-classes require some interaction by the user in order for them to apply, such as holding a mouse pointer over an element.

Functional pseudo-classes

These pseudo-classes accept a selector list or forgiving selector list as a parameter.

Syntax

selector:pseudo-class {
  property: value;
}

Like regular classes, you can chain together as many pseudo-classes as you want in a selector.

Alphabetical index

Pseudo-classes defined by a set of CSS specifications include the following:

A

B

C

D

E

F

H

I

L

M

N

O

P

R

S

T

U

V

W

Specifications

{{Specifications}} 

See also

In this article

View on MDN