CSS change button style after click

JohnyNich picture JohnyNich · Feb 9, 2017 · Viewed 226.3k times · Source

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!

Answer

Rich picture Rich · Feb 9, 2017

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

#style  {
    background-color: red;
}

#style:focus {     
    background-color:yellow;    
}