CSS Reference ยท Pseudo-classes
The :active pseudo-class
Reference for the CSS :active pseudo-class: style an element while it is being pressed, with syntax, the LVHA order, examples, usage notes and browser support.
The :active pseudo-class matches an element while the user is activating it. For a mouse that means the button is held down on the element; for the keyboard it usually means the Space or Enter key is held on a focused button or link. As soon as the press ends, the element stops matching.
It is the natural place for a "pressed" effect: a button that sinks a little, darkens, or loses its shadow so the interface feels responsive.
button:active { transform: translateY(2px); }
Try it
Syntax
:active { /* declarations */ }
:active takes no arguments and has the specificity of one pseudo-class (0,1,0). It is a state, not a property, so inheritance and animation do not apply to it directly; properties you set inside it follow their own rules, and a transition on the base rule will animate the change.
Syntax and arguments
| Part | Description |
|---|---|
:active |
Matches an element while it is being activated by the pointer or keyboard. |
| No arguments | The pseudo-class is not functional. |
| Combining | Attach it to a type, class or any selector: a.cta:active, :is(button, a):active. |
Usage notes
- Order matters for links.
:activehas the same specificity as:link,:visitedand:hover, so the last matching rule wins. Write link rules in the order:link,:visited,:hover,:active("LVHA") so each state can override the previous one. - Not just for buttons. Any element can match while pressed, but a pointer press on a non-interactive element like a
<div>is unusual to style. - Touch screens. Pressed feedback on touch depends on the browser and device; do not make
:activethe only sign that something happened. - Pair it with focus styles. Keyboard users see
:focus-visible, not the press state; give them their own indicator (see:focus-visible). - Avoid layout shifts. Prefer
transformorbox-shadowchanges overmarginorborder-width, which can move neighbouring content while the button is held.
Browser support
Supported in every browser.
Related
:hoverโ pointer over the element:focusโ element has focus:focus-visibleโ focus that needs an indicator- Lesson: Pseudo-classes