CSS on mouse down event.

CSS on Mouse Down

  • CSS
  • 1 min read

Use the :active CSS pseudo-class to style an element when the user presses down the left or primary mouse button.

Syntax

<element>:active {css-style}

Example 1

Changing the color of a link on mouse down:

a:active {color: red;}

Output

Click the following link and you will notice that on mouse down it will turn red. Test me

Example 2

Change the background color of a paragraph on click:

p:active {background-color: #eee;}

Output

Click on this paragraph and on mouse down its background color will change to light gray.
This is another line.

Reference

CSS - :active

Related Tutorials