CSS Pseudo-Classes Table

–click a pseudo-class to copy it
Pseudo-classMatches
:hoverElement under the pointer (does not require click)
:focusElement that has keyboard or programmatic focus
:focus-visibleFocus from keyboard only (not mouse click)
:activeElement being activated (mouse button held down)
:visitedLink that has already been visited
:first-childElement that is the first child of its parent
:last-childElement that is the last child of its parent
:nth-child(n)Element at position n among its siblings (supports odd, even, 2n+1)
:nth-of-type(n)Element at position n among siblings of the same type
:checkedCheckbox or radio button that is selected
:disabledForm element that is disabled
:requiredForm element with the required attribute
:invalidForm element that fails constraint validation
:placeholder-shownInput element currently showing placeholder text
:rootThe html element (useful for CSS custom properties)
:emptyElement with no children (including text nodes)
:not(selector)Element that does NOT match the given selector
:is(selector)Element matching any of the listed selectors (specificity of most specific)
:where(selector)Like :is() but contributes zero specificity
Pseudo-classes follow MDN's pseudo-classes reference. The two that changed modern CSS: :where() contributes zero specificity (perfect for base styles that should be easily overridden) and :is() takes the specificity of its most specific argument (perfect for grouped selectors without specificity explosion). Bottom line: :hover is not just for links - applying it to cards, buttons and table rows is the cheapest micro-interaction available; and :focus-visible solved the decade-old problem of focus rings appearing on mouse click. CSS hub: CSS flexbox table, CSS units table, CSS named colors, contrast ratio checker.

CSS pseudo-classes style elements based on state or position rather than class or ID - :hover for mouse interaction, :nth-child(2n) for every other row, :invalid for failed form validation. This table covers all 19 pseudo-classes verbatim from MDN, organised by what triggers them.

The two modern additions that changed the game: :focus-visible (focus rings only for keyboard users, not mouse clicks) and :where() (zero-specificity grouping that can be overridden by any class).

How to use

  1. Filter by pseudo-class name or category - hover, child, form, link - to find the one you need.
  2. Click any pseudo-class to copy it into your CSS.
  3. Read the matches column for the exact triggering condition - some are surprising (:focus fires on mouse click for inputs, but :focus-visible does not).

Frequently asked questions

What is the difference between :focus and :focus-visible?

:focus triggers whenever an element receives focus, including mouse clicks on inputs. :focus-visible only triggers when the browser determines the user is navigating by keyboard (typically Tab key). The result: keyboard users see focus rings, mouse users do not - solving the old problem of removing outline: none and breaking accessibility.

How does :nth-child(odd) work?

It selects every other element starting from the first: elements at positions 1, 3, 5, 7... The general form :nth-child(an+b) selects elements at positions a·n + b for n = 0, 1, 2... So :nth-child(2n) is even positions and :nth-child(2n+1) is odd positions. You can also use :nth-child(3) for exactly the third element.

What is the specificity difference between :is() and :where()?

:is() takes the specificity of its most specific argument, while :where() always contributes zero. This means :where(section, #sidebar) p has the same specificity as just p, making it perfect for reset styles that should be easily overridden by any class or utility.

Why does :first-child sometimes not match?

:first-child means the first child element of any type, not the first element of a specific type. If a div contains a text node followed by a p, the p is :first-child (text nodes are not elements). If it contains a span followed by a p, the p is NOT :first-child - the span is. Use :first-of-type for type-specific matching.

Related tools