CSS :focus selector
Complete CSS Selector Reference Manual
Example
Style selected when an input field gains focus:
input:focus
{
background-color:yellow;
}
Try it »
Definition and Usage
:focus selector is used to select the element that has focus.
Tip: :focus selector accepts keyboard events or other user input elements.
Browser support
The numbers in the table indicate the first browser version that supports this property.
| Selector | |||||
|---|---|---|---|---|---|
| :focus | 4.0 | 8.0 | 2.0 | 3.1 | 9.6 |
Note: The :focus selector requires a DOCTYPE declaration in IE8 .
Related Articles
CSS tutorial: CSS pseudo-classes