:hover

The :hover pseudo-class matches an element while the pointer is over it.

Since CSS1 Spec ↗

Syntax

selector:hover { }

Examples

.btn {
  background: royalblue;
  transition: background-color 0.15s;
}
.btn:hover { background: oklch(0.5 0.2 265); }
Output
Darkens the button background smoothly while the mouse is over it.

Notes

Hover does not exist on touch devices, so never make essential actions hover-only. Pair with :focus-visible for keyboard parity. Wrap in @media (hover: hover) to target true pointer devices.

Browser & runtime support

EnvironmentSince version
chrome 1.0
firefox 1.0
safari 1.0
edge 12

See also