CSS :focusSelectors

Complete CSS Selector Reference Manual

Example

The style to apply when an input field receives focus:

input:focus
{
background-color:yellow;
}

Try it Yourself »

Definition and Usage

The :focus selector is used to select elements that have focus.

Tip:The :focus selector selects elements that accept keyboard events or other user input.


Browser Support

The numbers in the table indicate the first browser version that supports the property.

Selectors
:focus 4.0 8.0 2.0 3.1 9.6

Note:The :focus selector must be declared in IE8.<!DOCTYPE> .


Related Articles

CSS tutorial: CSS Pseudo-classes


Complete CSS Selector Reference Manual

other extensions