CSS :active Pseudo-class
More "Try it Yourself" examples below.
Definition and Usage
The :active
pseudo-class is used to select and style
an element that is being activated by the user.
The :active
pseudo-class is most used on <a>
and <button> elements. A link becomes activated when the user clicks on it, the
same goes for a button.
Tip: Use :link to style links to unvisited pages, :visited to style links to visited pages, and :hover to style links when you mouse over them.
Note: :active
MUST come after :hover
(if present) in the CSS
definition in order to be effective!
Version: | CSS1 |
---|
Browser Support
The numbers in the table specifies the first browser version that fully supports the pseudo-class.
Pseudo-class | |||||
---|---|---|---|---|---|
:active | 4.0 | 7.0 | 2.0 | 3.1 | 9.6 |
CSS Syntax
:active {
css declarations;
}
More Examples
Example
Select and style a <button> when the user clicks on it:
button:active {
background-color: pink;
}
Try it Yourself »
Example
Select and style a <p>, <h1> and <a> element when you click on it:
p:active, h1:active, a:active {
background-color: yellow;
}
Try it Yourself »
Example
Select and style unvisited, visited, hover, and active links:
/* unvisited link */
a:link {
color: green;
}
/* visited link */
a:visited {
color: green;
}
/* mouse over link */
a:hover {
color: red;
}
/* selected link */
a:active {
color: yellow;
}
Try it Yourself »
Example
Style links with different styles:
a.ex1:hover, a.ex1:active {
color: red;
}
a.ex2:hover, a.ex2:active {
font-size: 150%;
}
Try it Yourself »
Related Pages
CSS tutorial: CSS Links
CSS tutorial: CSS Buttons
CSS tutorial: CSS Pseudo classes