CSS Selector - How to CSS active element Selector :active








The :active selector matches activating elements. The :active selector isn't limited to elements with which the user can interact.

:active is a Pseudo-class selector and it applies to an element that is being activated.

The most common example is clicking on a hyperlink in an HTML document: while the mouse button is being held down, the link is active.

Examples:

a:active  {color: red;}
*:active {background: blue;}

Summary

CSS Version
1

CSS Syntax

:active { 
   style properties 
}




Browser compatibility

:active Yes 7.0 Yes Yes Yes

Example

An example showing how to use :active CSS selector.

<!DOCTYPE HTML> 
<html> 
    <head> 
        <title>Example</title> 
        <style type="text/css"> 
        :active { <!--from  w  w  w.  ja v  a 2  s.c  o m-->
            border: thin black solid; 
            padding: 4px; 
        } 
        </style> 
    </head> 
    <body> 
        <a href="http://java2s.com">Visit the java2s.com</a> 
        <p>I like <span>HTML</span> and CSS.</p> 
        <button>Hello</button> 
    </body> 
</html>

Click to view the demo