Skip to content
Related Articles
Open in App
Not now

Related Articles

CSS :focus Selector

Improve Article
Save Article
  • Last Updated : 23 Aug, 2022
Improve Article
Save Article

The :focus CSS pseudo-class Selector is used to target the focused element ie., it selects an element that is currently focused by the user. This selector works on user input elements, generally used in forms, and is triggered as soon as the user clicks on it or taps on an element, or selects any keyboard events.


:focus {
  // CSS property

Example: This example illustrates the :focus selector to target the selected element.


<!DOCTYPE html>
    input:focus {
        background-color: limegreen;
    <h3>Fill this form</h3>
    <form> Full name:
        <input type="text"
               placeholder="Enter Name"
        <br> User Id:
        <input type="text"
               placeholder="Enter Username"
        <br> Password:
        <input type="password"
               placeholder="Enter Password"
        <button type="button"
                onclick="#">Sign Up</button>


Supported Browsers:

  • Google Chrome 1.0
  • Microsoft Edge 12.0
  • Firefox 1.0
  • Safari 1.0
  • Opera 7.0

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!