Ensuring a Value Is Within Bounds

You use the min and max attributes to ensure that numeric and date values are within a specific range. You need not apply both attributes. The min and max values are inclusive.

The min and max attributes only result in validation when there is a value. The browser will allow the user to submit the form if the text box is empty. For this reason, the mix and max attributes are often used in conjunction with the required attribute.

 
<!DOCTYPE HTML>
<html>
<head>
<title>Example</title>
</head>
<body>
      <form method="post" action="http://yourServer/form">
            <input type="hidden" name="recordID" value="1234" />
            <p>
                  <label for="name"> Name: <input type="text" id="name"
                        name="name" />
                  </label>
            </p>
            <p>
                  <label for="price"> $ per unit in your area: <input
                        type="number" min="0" max="100" value="1" id="price" name="price" />
                  </label>
            </p>
            <input type="submit" value="Submit" />
      </form>
</body>
</html>
  
Click to view this demo.
Home 
  HTML CSS Book 
    HTML  

Input Validation:
  1. Using Input Validation
  2. Ensuring the User Provides a Value
  3. Ensuring a Value Is Within Bounds
  4. Ensuring a Value Matches a Pattern
  5. Ensuring a Value Is an E-mail Address or URL
  6. Disabling Input Validation
Related: