Pseudo-classes start with a colon : and describe some "state" or "structural position" of an element — a state that usually cannot be expressed directly through a class or the HTML structure, such as whether the mouse is hovering over it or whether it is the first child element.
Interaction State Pseudo-classes
Pseudo-class
Trigger condition
:hover
The mouse is hovering over the element
:active
The instant the element is pressed
:focus
The element gains keyboard / programmatic focus
:focus-visible
Only triggers when the focus should be presented "visibly" (e.g. keyboard Tab)
AccessibilityAlways keep a visible outline for :focus-visible — keyboard users rely on it to know where the focus is; removing it causes serious usability problems.
Pitfall:nth-child counts among "all sibling elements", regardless of tag type; if you only want to count among siblings of the same type, use :nth-of-type.
Other commonly used ones include :placeholder-shown (when the placeholder is visible) and :in-range / :out-of-range (whether the value is within the min/max range) — all of which provide visual validation feedback without any JavaScript.
Logical Combination Pseudo-classes
CSS provides four "functional" pseudo-classes that combine other selectors like logical operators:
Pseudo-class
Purpose
:not(s)
Excludes elements matching s
:is(s1, s2)
Matches any s; specificity is the highest among the arguments
:where(s1, s2)
Same as :is, but specificity is always 0
:has(s)
Matches elements that contain s inside (the parent selector)
/* Give cards containing an image extra padding — :has makes "selecting a parent by its child" possible */.card:has(img) {
padding-bottom: 0;
}