The :active CSS pseudo-class represents an element (such as a button) that is being activated by the user. When using a mouse, "activation" typically starts when the user presses down the primary mouse button.
:active
Baseline Widely available
This feature is well established and works across many devices and browser versions. Itβs been available across browsers since July 2015.
Try it
.joinBtn {
width: 10em;
height: 5ex;
background-image: linear-gradient(135deg, #f34079 40%, #fc894d);
border: none;
border-radius: 5px;
font-weight: bold;
color: white;
cursor: pointer;
}
.joinBtn:active {
box-shadow: 2px 2px 5px #fc894d;
}
<p>Would you like to subscribe to our channel?</p> <button class="joinBtn">Subscribe</button>
The :active pseudo-class is commonly used on <a> and <button> elements. Other common targets of this pseudo-class include elements that are contained in an activated element, and form elements that are being activated through their associated <label>.
Styles defined by the :active pseudo-class will be overridden by any subsequent link-related pseudo-class (:link, :hover, or :visited) that has at least equal specificity. To style links appropriately, put the :active rule after all other link-related rules, as defined by the LVHA-order: :link β :visited β :hover β :active.
Note: On systems with multi-button mice, CSS specifies that the :active pseudo-class must only apply to the primary button; on right-handed mice, this is typically the leftmost button.
Syntax
:active {
/* ... */
}
Examples
Active links
HTML
<p> This paragraph contains a link: <a href="#">This link will turn red while you click on it.</a> The paragraph will get a gray background while you click on it or the link. </p>
CSS
/* Unvisited links */
a:link {
color: blue;
}
/* Visited links */
a:visited {
color: purple;
}
/* Hovered links */
a:hover {
background: yellow;
}
/* Active links */
a:active {
color: red;
}
/* Active paragraphs */
p:active {
background: #eee;
}
Result
Active form elements
HTML
<form> <label for="my-button">My button: </label> <button id="my-button" type="button">Try Clicking Me or My Label!</button> </form>
CSS
form :active {
color: red;
}
form button {
background: white;
}
Result
Specifications
| Specification |
|---|
| HTML # selector-active |
| Selectors Level 4 # active-pseudo |
Browser compatibility
| Desktop | Mobile | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | |
:active |
1 | 12 | 1 | 5 | 1 | 18 | 4 | 10.1 | 1 | 1.0 | 4.4 |
non_a_elements |
1 | 12 | 1 | 7 | 1 | 18 | 4 | 14 | 1By default, Safari on iOS does not use the:active state unless there is a touchstart event handler on the relevant element or on the <body> element. |
1.0 | 4.4 |
See also
© 2005–2024 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/:active