CSS :active Pseudo-Class

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The :active pseudo-class matches an element while the user is activating it— usually while the primary mouse button is held down or a finger is pressing.

It is most often used on <a> and <button>. It can also match nested content inside an activated element, and form controls activated through a linked <label>.

Note Not the “current page”

:active is only the press state. It does not mean “this is the active menu item.” Style the current page with a class or :target pattern instead.

Note LVHA order for links

Put link rules in this order: :link → :visited → :hover → :active, so the pressed style can override hover.

CSS Syntax

syntax.css
selector:active { /* styles while pressed */ }

No arguments. Pair it with an element or class selector, for example button:active or a:active.

Selector Patterns

PatternDescriptionTry it
button:activeStyles a button while it is pressedTry it
a:activeStyles a link during activation (after LVHA)Try it
p:activeParagraph (or other box) while pressedTry it
.btn:activeClass-scoped pressed stateTry it

How to Use :active

Give a clear default, then a short pressed feedback style.

  1. Style the normal button or link first.
  2. Add :hover for pointer-over feedback (optional).
  3. Add :active last for the press look (darker, slightly inset, and so on).
  4. For links, keep LVHA: :link, :visited, :hover, :active.
PieceRequired?Role
Base selectorYesWhich element gets the pressed style
:activeYesMatches only while activating
Visible changeYesColor, scale, or shadow so the press is obvious
LVHA orderFor linksLets :active win over :hover

Live Preview

Click and hold the controls below. Real :active CSS styles apply while the pointer is down.

Press feedback

Hold the mouse button (or finger) to see the active state. Release to clear it.

Active preview

Styles come from button:active and a:active in the shared stylesheet.

CSS Examples

Each snippet focuses on :active. Use Try It Yourself for a live editor—click and hold in the preview.

Example 1 — Button Press

Darken a button while it is held down.

CSS
button {
  background: #2563eb;
  color: white;
}

button:active {
  background: #1e3a8a;
}
Try It Yourself

How It Works

  1. Style the default. Blue background is the resting look.
  2. Add :active. The rule matches only while pressing.
  3. Darken the fill. Navy background shows the press.
  4. Release clears it. The state ends when the pointer goes up.

Example 3 — Press Any Box

:active is not limited to buttons and links.

CSS
p {
  background: #e2e8f0;
}

p:active {
  background: #cbd5e1;
}
Try It Yourself

How It Works

  1. Style the box. Light gray is the resting look.
  2. Target p:active. Any press on the paragraph matches.
  3. Darken briefly. Shows that activation is not only for controls.
  4. Prefer real controls. For accessibility, use buttons/links for actions.

Edge Cases & Pitfalls

Short-lived state—easy to miss if order or meaning is wrong.

myth

Not “current page”

Do not use :active to highlight the nav item for the page you are on. Use a class (or similar) for that.

order

Put :active after :hover

Otherwise equal-specificity hover rules can hide the pressed style on links.

mouse

Primary button only

CSS applies :active to the primary mouse button (usually the left button), not every mouse button.

touch

Brief on touch devices

The state can flash quickly on tap. Keep the change clear and avoid relying on it alone for critical feedback.

focus

Also style :focus / keyboard

Keyboard users need focus styles. Pair with :focus (and consider focus-visible patterns) for full interaction feedback.

Browser Support

:active is a browser CSS pseudo-class. Node.js, Deno, and Bun do not evaluate it.

✓ Baseline · Widely available

:active

Supported in all major browsers for decades (Baseline Widely available since about July 2015). Safe for everyday UI press feedback.

99% All modern browsers
Google Chrome All
Full
Mozilla Firefox All
Full
Apple Safari All
Full
Microsoft Edge All
Full
Opera All
Full
Samsung Internet All
Full
Internet Explorer All
Full
:active Universally supported

Bottom line: Production-ready. Remember LVHA order for links, and do not confuse :active with the current page.

Key Takeaways

  • Role: style the element while it is being pressed/activated.
  • Targets: buttons, links, and other activated elements.
  • Order: LVHA — put :active last for links.
  • Tip: not for current-page highlighting; keep keyboard :focus styles too.

One line: :active is the brief pressed state—style it after :hover, and do not confuse it with the current page.

Frequently Asked Questions

It styles an element while the user is activating it—typically while the primary mouse button is held down or a finger is pressing.
No. That is a common myth. :active is only the press/activation state, not “this is the active menu item.”
:hover applies while the pointer is over the element. :active applies only during the press, before release.
For links, use LVHA order: :link, :visited, :hover, :active. Later rules with equal specificity win, so :active must be last to show while pressing.
Buttons and links are the usual targets. It can also match other elements being activated, nested content inside an active element, and controls activated via a linked label.
No. It is a browser CSS pseudo-class, not a Node.js feature.

Next: :checked

Learn how to style checked form controls with CSS.

:checked tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful