Languages
[Edit]
EN

CSS - input background color change on focus

0 points
Created by:
Rogan-Wilkes
727

In this article, we would like to show you how to change input background color on focus using CSS.

Quick solution:

input:focus {
    background: lightgreen; 
}

 

Practical example

In this example, we use CSS :focus pseudo class to change input background color on focus event.

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<head>
  <style>

    input:focus {
        background: lightgreen; 
    }

  </style>
</head>
<body>
  <form onsubmit="return false;">
    <input type="text" />
    <input type="submit" value="Submit" />
  </form>
</body>
</html>

Note:

This approach affects all types of inputs.

 

References

  1. :focus - CSS: Cascading Style Sheets | MDN
  2. <input>: The Input (Form Input) element - HTML: HyperText Markup Language | MDN
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join