HTML/CSSBeginner#css#pseudo-classes

What is the difference between :hover, :focus, and :active pseudo-classes?

:hover applies while the pointer is over an element. :focus applies when an element has keyboard/programmatic focus (crucial for accessibility, e.g. tabbing to a button). :active applies during the moment of activation, like a mouse button held down or a link being clicked.

Example
button:hover { background: #ddd; }
button:focus-visible { outline: 2px solid blue; }
button:active { transform: scale(0.98); }

Related Questions

1
HTML/CSSAdvanced#css#pseudo-classes

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

Open
2
HTML/CSSIntermediate#css#accessibility

How do you make an SVG icon accessible and stylable with CSS?

Open
3
HTML/CSSAdvanced#css#responsive

What is the difference between em/rem and viewport-relative clamp() for fluid typography?

Open