EN
CSS - input background color change on focus
0
points
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.