Pseudo classes
Pseudo class selector specifies a special state of the selected element(s).
Links
Styles defined by these selectors can be overridden by each other. To style links properly use LVHA-order: :link — :visited — :hover — :active.
name | description |
---|---|
:link | Represents an element that has not yet been visited. It matches every unvisited a, area or link element that has an href attribute. |
:visited | Represents links that the user has already visited. For privacy reasons, the styles that can be modified using this selector are very limited. |
:hover | Matches when the user interacts with an element with a pointing device, but does not necessarily activate it. It is generally triggered when the user hovers over an element with the cursor (mouse pointer). |
:active | Represents an element that is being activated by the user. When using a mouse, "activation" typically starts when the user presses down the primary mouse button. Usually used with a and button elements. |
Selecting child elements
name | description |
---|---|
:empty | Represents any element that has no children. Children can be either element nodes or text, including whitespace. Comments, processing instructions, and CSS content do not affect whether an element is considered empty. |
:first-child | Represents the first element among a group of sibling elements. |
:first-of-type | Represents the first element of its type among a group of sibling elements.
|
:nth-child(n) | Matches elements based on their position in a group of siblings.
See more examples.
|
:nth-of-type(n) |
Matches elements of a given type, based on their position among a group of siblings.
|
:nth-last-child(n) | Matches elements based on their position among a group of siblings, counting from the end. n like at :nth-child(n). |
:nth-last-of-type(n) | Matches elements of a given type, based on their position among a group of siblings, counting from the end. n like :nth-of-type(n) |
:last-child | Represents the last element among a group of sibling elements. |
:last-of-type | Represents the last element of its type among a group of sibling elements. |
:only-child | Represents an element without any siblings. |
:only-of-type | Represents an element that has no siblings of the same type. |
Selecting elements of form
name | description |
---|---|
:checked | Represents an element that has not yet been visited. It matches every unvisited a, area or link element that has an href attribute. |
:disabled | Represents any disabled element. An element is disabled if it can't be activated (selected, clicked on, typed into, etc.) or accept focus. The element also has an enabled state, in which it can be activated or accept focus. |
:enabled | Represents any enabled element. An element is enabled if it can be activated (selected, clicked on, typed into, etc.) or accept focus. The element also has a disabled state, in which it can't be activated or accept focus. |
:focus | Represents an element (such as a form input) that has received focus. It is generally triggered when the user clicks or taps on an element or selects it with the keyboard's "tab" key. |
:in-range | Represents an input element whose current value is within the range limits specified by the min and max attributes. |
:invalid | Represents any input or other form element whose contents fail to validate. |
:optional | Represents any input, select, or textarea element that does not have the required attribute set on it. |
:out-of-range | Represents an input element whose current value is outside the range limits specified by the min and max attributes. |
:read-only | Represents an element input or textarea that is not editable by the user. |
:read-write | Represents an element input or textarea that is editable by the user. |
:required | Represents any input, select or textarea element that has the required attribute set on it. It is useful for highlighting fields that must have valid data before a form can be submitted. |
:valid | represents any input or other form element whose contents validate successfully. It is useful for highlighting correct fields for the user. |
Other pseudo classes
name | description |
---|---|
:lang(l) | Matches elements based on the language they are determined to be in.
|
:not | Represents elements that do not match a list of selectors. The list must not contain another negation selector or a pseudo selector. The ability to list more than one selector is experimental and not yet widely supported. |
:root | Matches the root element of a tree representing the document. So in HTML document it is html element. |