property - how to keep:active css style after click a button

CSS change button style after click (4)

I was wondering if there was a way to change a button's style, in css, after it's been clicked, so not a element:active. Thanks!

Each link has five different states: link, hover, active, focus and visited.

Link is the normal appearance, hover is when you mouse over, active is the state when it's clicked, focus follows active and visited is the state you end up when you unfocus the recently clicked link.

I'm guessing you want to achieve a different style on either focus or visited, then you can add the following CSS:

a { color: #00c; }
a:visited { #ccc; }
a:focus { #cc0; }

A recommended order in your CSS to not cause any trouble is the following:

a:visited { ... }
a:focus { ... }
a:hover { ... }
a:active { ... }

You can use your web browser's developer tools to force the states of the element like this (Chrome->Developer Tools/Inspect Element->Style->Filter :hov): Force state in Chrome Developer Tools

If you're looking for a pure css option, try using the :focus pseudo class.

#style  {
    background-color: red;

#style:focus {     

It is possible to do with CSS only by selecting active and focus pseudo element of the button.



See codepen:

You could also write a simple jQuery click function which changes the background color.


<button class="js-click">Click me!</button>


button {
  background: none;


  $( ".js-click" ).click(function() {
    $( ".js-click" ).css('background', 'green');

Check out this codepen:

Try to check outline on button's focus:

button:focus {
    outline: blue auto 5px; 

If you have it, just set it to none.