Language
日本語
English

Caution

JavaScript is disabled in your browser.
This site uses JavaScript for features such as search.
For the best experience, please enable JavaScript before browsing this site.

CSS Dictionary

  1. Home
  2. CSS Dictionary
  3. [CSS Selector] E:focus

[CSS Selector] E:focus

Using selector:focus, you can apply styles to the element that is currently focused. "Focused" refers to a state where a form input is active or an element such as an anchor is selected via the keyboard Tab key. This is commonly called a "pseudo-class" (:focus pseudo-class).

Sample Code

input:focus { background-color: yellow;} /* Makes the background of a focused (active) input element yellow. */

Browser Preview

input:focus { background-color: yellow;} /* Makes the background of a focused (active) input element yellow. */

<p>The background color changes while typing: <input type="text"></p>

Browser Compatibility

Chrome Chrome
1+
Firefox Firefox
1+
Safari Safari
1+
Edge Edge
12+
Supported in all versions
IE IE
11
10
9
8
7 ×
6 ×
Opera Opera
7+
6 or earlier ×
iOS Safari iOS Safari
1+
Android Android Browser
4.4+
3 or earlier ×
Chrome Android Chrome Android
Latest
Same support as desktop version
Firefox Android Firefox Android
Latest
Same support as desktop version

※ Version data based on MDN.

If you find any errors or copyright issues, please .