Pseudo-classes
suggest changePseudo-classes are keywords which allow selection based on information that lies outside of the document tree or that cannot be expressed by other selectors or combinators. This information can be associated to a certain state (state and dynamic pseudo-classes), to locations (structural and target pseudo-classes), to negations of the former (negation pseudo-class) or to languages (lang pseudo-class). Examples include whether or not a link has been followed (:visited), the mouse is over an element (:hover), a checkbox is checked (:checked), etc.
Syntax
selector:pseudo-class {
property: value;
}
List of pseudo-classes:
Name | Description |
–– | ———– |:active | Applies to any element being activated (i.e. clicked) by the user. |:any | Obsolete. Use :is() to group selectors instead of repeating them. |:target | Selects the current active #news element (clicked on a URLcontaining that anchor name) |:checked | Applies to radio, checkbox, or option elements that are checkedor toggled into an “on” state. |:default | Represents any user interface element that is the default among a group ofsimilar elements. |:disabled | Applies to any UI element which is in a disabled state. |:empty | Applies to any element which has no children. |:enabled | Applies to any UI element which is in an enabled state. |:first | Used in conjunction with the @page rule, this selects the first page in aprinted document. |:first-child | Represents any element that is the first child element of its parent. |:first-of-type | Applies when an element is the first of the selected element typeinside its parent. This may or may not be the first-child. |:focus | Applies to any element which has the user’s focus. This can be given by theuser’s keyboard, mouse events, or other forms of input. |:focus-within | Can be used to highlight a whole section when one element inside it is focused. It matches any element that the :focus pseudo-class matches or that has a descendant focused. |:fullscreen | Matches an element that is displayed fullscreen, and the ancestors that form the fullscreen stack. The standard name is :fullscreen, not :full-screen. |:hover | Applies to any element being hovered by the user’s pointing device, butnot activated. |:indeterminate | Applies radio or checkbox UI elements which are neither checked norunchecked, but are in an indeterminate state. This can be due to anelement’s attribute or DOM manipulation. |:in-range | The :in-range CSS pseudo-class matches when an element hasits value attribute inside the specified range limitations for this element.It allows the page to give a feedback that the value currently definedusing the element is inside the range limits. |:invalid | Applies to <input> elements whose values are invalid according tothe type specified in the type= attribute. |:lang() | Matches an element written in the given language, based on its own lang or an ancestor’s, not only the <body>. The argument is a language code such as en or fr. |:last-child | Represents any element that is the last child element of its parent. |:last-of-type | Applies when an element is the last of the selected element type insideits parent. This may or may not be the last-child. |:left | Used in conjunction with the @page rule, this selects all the leftpages in a printed document. |:link | Applies to any links which haven’t been visited by the user. |:not() | Applies to all elements which do not match the value passed to(:not(p) or :not(.class-name) for example. It needs a selector argument. A selector list inside one :not() is valid (:not(p, .note)); chaining separate :not() selectors also works. |:nth-child | Applies when an element is the n-th element of its parent, where ncan be an integer, a mathematical expression (e.g n+3) or the keywordsodd or even. |:nth-of-type | Applies when an element is the n-th element of its parent of thesame element type, where n can be an integer, a mathematicalexpression (e.g n+3) or the keywords odd or even. |:only-child | The :only-child CSS pseudo-class represents any elementwhich is the only child of its parent. This is the same as:first-child:last-child or :nth-child(1):nth-last-child(1),but with a lower specificity. |:optional | The :optional CSS pseudo-class represents any elementthat does not have the required attribute set on it. This allowsforms to easily indicate optional fields and to style them accordingly. |:out-of-range | The :out-of-range CSS pseudo-class matches when an element has itsvalue attribute outside the specified range limitations for this element.It allows the page to give a feedback that the value currently defined using theelement is outside the range limits. A value can be outside of a range if it iseither smaller or larger than maximum and minimum set values. |:placeholder-shown | Matches a form control that is currently showing its placeholder. |:read-only | Applies to any element which is not editable by the user. |:read-write | Applies to any element that is editable by a user, such as <input> elements. |:right | Used in conjunction with the @page rule, this selects all the right pages in aprinted document. |:root | matches the root element of a tree representing the document. |:scope | CSS pseudo-class matches the elements that are a referencepoint for selectors to match against. |:target | Selects the current active #news element (clicked on a URLcontaining that anchor name) |:visited | Applies to links the user has visited. Browsers heavily limit which properties :visited may change. |
The :visited pseudoclass can’t be used for most styling in a lot of modern browsers anymore because it’s a security hole. See this link for reference.