[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
Desktop
Supported in all versions
8 ○
7 ×
6 ×
6 or earlier ×Mobile
Android Browser
4.4+ ○
3 or earlier ×Same support as desktop version
Same support as desktop version
※ Version data based on MDN.
If you find any errors or copyright issues, please contact us.