Skip to the page
css reference · selectors

CSS :hover / :first-child

type
pseudo-class
applies to
an element based on state or position, not markup
inherits
n/a
common values
:hover, :focus, :first-child, :last-child, :nth-child()

Where it goes

Stuck directly onto the end of a selector, with no space before the colon.

Example

button:hover, button:focus {
  opacity: 0.8;
}

Common mistakes

  • Expecting :hover to work like a tap on a phone. Touch screens have no hover, so that state may never show.
  • Styling :hover without a matching :focus. Someone moving through the page with the keyboard never hovers, and loses the same visual cue.

Related

Updated 24 October 2026. Practice it in the css route, or read more on MDN.