abhi
abhi

Reputation: 31

button color change by tab key press

I have a button and I want it to change to green when I access it by tab key. I have written the code for hover by mouse but I want that when a user a goes to the button using tab key then it should change the color.

Upvotes: 1

Views: 4343

Answers (1)

SW4
SW4

Reputation: 71240

Simply use the :focus pseudo selector

Demo Fiddle

button:focus{
    color:green;
}

More on :focus from MDN

The :focus CSS pseudo-class is applied when a element has received focus, either from the user selecting it with the use of a keyboard or by activating with the mouse (e.g. a form input).

You may also wish to give the button a tabindex attribute to control its tab order.

Upvotes: 6

Related Questions