CSS :focus Selector

❮ Previous Selectors Next ❯


.example:focus { 
  background-color: red;


The :focus selector matches any element that has keyboard input focus.

It is generally triggered when the user clicks or taps on an element or selects it with the keyboard's Tab key.

It can apply to a form control, for instance, or to a link if the user navigates using the keyboard.

Note: This pseudo-class applies only to the focused element itself. Use :focus-within if you want to select an element that contains a focused element.

Version: CSS2

Standard Syntax

:focus {
  css declarations;

Browser Support

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


❮ Previous Selectors Next ❯