user8156106
user8156106

Reputation:

how to change button color when clicked

I am new css and I am having hard time changing the color of the button when clicked. Normally, when a button is clicked, the button color becomes blue for a very short period of time. I want it instead to be yellow. How can I achieve that?

html

<button id="btn">Hi</button>

Upvotes: 1

Views: 972

Answers (1)

Dhruvil21_04
Dhruvil21_04

Reputation: 2189

It's very easy. You can get this by :active and :focus states. Just try the below snippet. (You can change the colors as per your needs.)

button {
    background: #0095ff;
    border: none;
    padding: 10px 20px;
    color: #fff;
    outline: none;
}

button:active, button:focus  {
    background: yellow;
    color: #000;
}
<button>Click Me!</button>

As you are new to CSS, if you need then you can read this if you want to:* https://developer.mozilla.org/en-US/docs/Web/CSS

Upvotes: 2

Related Questions