:active
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.
Try it
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
css
:active {
/* ... */
}
Examples
Active links
HTML
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
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
html
<form>
<label for="my-button">My button: </label>
<button id="my-button" type="button">Try Clicking Me or My Label!</button>
</form>
CSS
css
form :active {
color: red;
}
form button {
background: white;
}
Result
Specifications
Specification |
---|
HTML Standard # selector-active |
Selectors Level 4 # the-active-pseudo |
Browser compatibility
BCD tables only load in the browser