Set min/max value for input field with CSS


Is there a way to set the min/max values of a HTML input form based on the ID with CSS?


You can do this by getting the input’s DOM node:
Every time the input loses focus, determine whether the value is within the range you specified, if not, correct it and prompt

function change(){
        const searchBox = document.getElementById("myInput");
      alert("the max value is 100")
        alert("the min value is 0")
<input type="text" value="" id="myInput" onBlur="change">

If you want to change the style by changing the ID:
Then you can first get his DOM through class, and then you can forcefully modify his id according to

But it is not recommended to do so

Answered By – ConstFiv

Answer Checked By – Katrina (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.