You can style input elements with CSS based on their validity with the in-range
and out-of-range
pseudo-class selectors:
<!-- ๐ This will make the background of the input green -->
<style>
input:in-range {
background-color: green;
}
</style>
<input type="number" min="1" max="10" value="5" />
Copied to clipboard!
<!-- ๐ This will make the background of the input red -->
<style>
input:out-of-range {
background-color: red;
border: 2px solid red;
}
</style>
<input type="number" min="1" max="10" value="12" />
Copied to clipboard!
Make sure you always give feedback to your users about the action they take.


Resources:
Remove ads๐ Get access to exclusive content
Want to get access to exclusive content? Support webtips with the price of a coffee to get access to tips, checklists, cheatsheets, and much more. โ
Get access