Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

:active — activation pseudo-class

The :active pseudo-class matches an element during user activation, such as while a mouse button is held down on a button. It describes a temporary state, not a persistent selection.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate

Syntax

E:active { /* declarations */ }

:active is a pseudo-class with no arguments. The selector button:active matches a button during user activation, typically between pressing and releasing the primary mouse button. The CSS rule only changes appearance; it does not trigger the element's action.

Activation is not limited to the mouse. HTML defines it according to the element and interaction: a button activated with Space can match between keydown and keyup. Do not assume identical behavior for every key or device.

:active does not mean the current page or a persistent selection. It also differs from :hover and :focus: pointing and focus can continue without activation. Matching propagates from the activated element up the flat tree, which accounts for Shadow DOM content distribution. If there is a top-layer element on that path, matching includes the first such element but does not propagate to its ancestors, even if they are in the same flat tree. In HTML, a control associated with a label also matches when that label matches :active.

If you want to try the example in your own browser, hold the primary mouse button down over Hold me: the background should become dark and the text white. Releasing restores the resting colors. Then focus the button with Tab and try holding down Space.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>:active demo</title>
<style>
  button {
    background: #eeeeee;
    color: #111111;
    border: 2px solid #111111;
    padding: 12px 24px;
  }

  button:active {
    background: #111111;
    color: #ffffff;
  }
</style>
<button type="button">Hold me</button>
</html>

Result

At rest: light gray button with dark text. While the primary mouse button is held down over the button: dark background with white text. After release: the resting colors return.

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources