CSS :focus Pseudo-class
Example
Select and style an input field when it gets focus:
input:focus
{
background-color: yellow;
}
Try it Yourself »
More "Try it Yourself" examples below.
Definition and Usage
The :focus
pseudo-class
is used to select and style the element that gets focus.
Version: | CSS2 |
---|
Browser Support
The numbers in the table specifies the first browser version that fully supports the pseudo-class.
Pseudo-class | |||||
---|---|---|---|---|---|
:focus | 4.0 | 8.0 | 2.0 | 3.1 | 9.6 |
CSS Syntax
More Examples
Example
Change background color and width when an input field gets focus:
input:focus {
background-color: yellow;
width: 250px;
}
Try it Yourself »
Related Pages
CSS tutorial: CSS Pseudo classes