CSS :active Selector

Beginner
⏱️ 6 min read
📚 Updated: Jun 2026
🎯 4 Examples
Interaction States

What You’ll Learn

The :active pseudo-class styles an element while the user is pressing or tapping it. It is one of the easiest ways to give buttons and links instant visual feedback.

01

Press feedback

Style clicks and taps.

02

Syntax

element:active

03

Buttons & links

Most common targets.

04

:hover combo

Layer interaction states.

05

Short duration

Only while pressed.

06

UX polish

Make UI feel responsive.

Introduction

The :active selector in CSS is used to style an element when it is being activated by the user. This typically happens when someone clicks a button, taps a link, or presses a form control.

The :active pseudo-class applies styles only during the interaction itself, giving users clear visual feedback that their action was received.

Definition and Usage

Use :active on interactive elements such as <button>, <a>, and <input> to darken a background, shrink an element slightly, or change color while pressed. The effect disappears as soon as the user releases the mouse button or lifts their finger.

💡
Beginner Tip

:active is not the same as :hover. Hover means the pointer is resting on the element; active means the user is currently pressing it. Use both together for polished buttons.

📝 Syntax

The syntax for the :active pseudo-class is straightforward:

syntax.css
element:active {
  /* CSS properties */
}

Basic Example

active.css
button:active {
  background-color: #1d4ed8;
  transform: scale(0.98);
}

Syntax Rules

  • Append :active directly to a selector with no space before the colon.
  • Works on buttons, links, inputs, and custom interactive components.
  • Styles apply only while the press or tap is in progress.
  • Combine with :hover and :focus for full interaction coverage.
  • Place :active after :hover when both change the same property.

Related Selectors

  • :hover — styles when the pointer is over an element
  • :focus — styles when an element has keyboard focus
  • :focus-visible — focus ring for keyboard users only
  • :link and :visited — unvisited and visited link states

⚡ Quick Reference

QuestionAnswer
Selector typePseudo-class
When it appliesWhile the user is pressing or tapping
Common targetsbutton, a, input
Typical effectsDarker color, scale(), shadow change
DurationOnly during the press (very brief)
Browser supportAll modern browsers

When to Use :active

:active is ideal whenever you want immediate press feedback:

  • Primary buttons — Show a darker shade or slight shrink on click.
  • Navigation links — Confirm the tap on mobile menus and tabs.
  • Icon buttons — Add a quick scale or opacity change on press.
  • Custom controls — Sliders, chips, and cards that behave like buttons.
  • Form submit actions — Reassure users their click registered.
button:active a:active .card-btn:active input[type="submit"]:active

👀 Live Preview

Click and hold the button or link below to see :active in action:

Active Link

Examples Gallery

Practice :active with buttons, links, combined states, and press-down effects.

📜 Core Patterns

Style buttons and links while the user is clicking or tapping.

Example 2 — Combine :hover, :focus, and :active

Layer pseudo-classes so hover, keyboard focus, and press each have a distinct look.

combined-states.css
button:hover,
button:focus {
  background-color: #1d4ed8;
}

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

How It Works

:hover and :focus share a medium-dark blue. :active goes even darker while the button is pressed, creating a clear three-step interaction.

📄 Advanced Patterns

Avoid specificity issues and build tactile press effects.

Example 3 — Pseudo-class order on links

Declare :active after :hover so the pressed state is not overridden unexpectedly.

link-order.css
a:hover {
  background-color: #2563eb;
  color: white;
}

a:active {
  background-color: #1d4ed8;
}
Try It Yourself

How It Works

When both :hover and :active match, the rule that appears later in the stylesheet wins if specificity is equal. Putting :active last keeps the pressed color visible.

Example 4 — Press-down button effect

Use transform and box-shadow together to simulate a physical button press.

press-effect.css
.card-btn {
  box-shadow: 0 4px 0 #1d4ed8;
  transform: translateY(0);
}

.card-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #1d4ed8;
}
Try It Yourself

How It Works

The shadow creates depth. On :active, the button shifts down and the shadow shrinks, mimicking a real press.

⚠️ Common Pitfalls

  • Short duration:active lasts only while the mouse or finger is down. Test by clicking and holding, not just clicking quickly.
  • Order matters — If :hover is declared after :active with the same specificity, hover can override the pressed look while the pointer is still over the element.
  • Non-interactive elements:active on a plain div only works if you add interaction (for example tabindex="0" or JavaScript handlers).
  • Overdoing motion — Large scale or movement changes can feel jarring. Subtle shifts work best.

♿ Accessibility

  • Do not rely on color alone — Pair color changes with size, shadow, or outline so low-vision users notice the state.
  • Keep :focus visible:active is not a replacement for keyboard focus styles. Always style :focus or :focus-visible too.
  • Avoid removing outlines — Never use outline: none without providing an accessible alternative.
  • Respect reduced motion — Consider @media (prefers-reduced-motion: reduce) for large transforms on press.

🧠 How :active Works

1

User presses an element

A mouse click, tap, or keyboard activation starts the interaction.

Input
2

Browser matches :active

While the press continues, the element matches the :active pseudo-class.

Match
3

Active styles are applied

Your CSS changes color, shadow, or transform for instant feedback.

Render
=

Responsive-feeling UI

Users see immediate confirmation that their action registered.

Browser Compatibility

The :active pseudo-class is supported in all major browsers, including Chrome, Firefox, Safari, Edge, and Opera.

Universal · All browsers

Press states everywhere

:active has been part of CSS since the earliest days of the web and works consistently across platforms.

99% Browser support
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions
Full support
Opera All versions
Full support
:active pseudo-class 99% supported

Bottom line: :active is safe to use in any modern project for click and tap feedback.

Conclusion

The CSS :active selector is a simple but powerful tool for giving users visual feedback when they interact with clickable elements. A darker shade or slight shrink on press makes buttons and links feel responsive and intentional.

Remember that :active only lasts during the press. Combine it with :hover and :focus for a complete interaction story, and keep effects subtle for the best user experience.

💡 Best Practices

✅ Do

  • Use :active on buttons and links for press feedback
  • Combine with :hover and :focus for full coverage
  • Place :active after :hover in your CSS file
  • Keep transforms and color shifts subtle
  • Test on touch devices as well as desktop

❌ Don’t

  • Expect :active to stay visible after the click ends
  • Remove focus outlines without a replacement
  • Use extreme scale values that shift layout
  • Forget pseudo-class order when styles conflict
  • Rely on press color as the only state indicator

Key Takeaways

Knowledge Unlocked

Five things to remember about :active

Use these points when styling interactive elements.

5
Core concepts
🔨 02

Buttons & links

Most common use.

Targets
🔀 03

With :hover

Layer states together.

Pattern
04

Brief state

Ends on release.

Timing
🌐 05

99% support

All browsers.

Compat

❓ Frequently Asked Questions

The :active pseudo-class applies styles while the user is actively pressing or tapping an element, such as during a mouse click or touch gesture.
Interactive elements like buttons, links, and form controls respond to :active. You can also use it on any element that receives pointer interaction.
Only while the mouse button or finger is held down on the element. When the user releases, the element returns to its normal or hover state.
:hover applies when the pointer is over an element. :active applies only during the actual press or click action.
Usually place :active after :hover in your stylesheet so the pressed state can override hover styles when both could apply.

Practice in the Live Editor

Open the HTML editor and experiment with :active, :hover, and :focus on buttons and links.

HTML Editor →

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.

5 people found this page helpful