Computer >> Computer tutorials >  >> Programming >> HTML

How to use min and max attributes in HTML?


The min and max attributes in HTML are used to set the minimum and maximum value of an element. The min and max attribute can be used on the following elements:

S. No
ElementsAttributeAttribute
1
<input>
Max
min
2
<meter>
Max
min
3
<progress>
Max
min


How to use min and max attributes in HTML?

Example

You can try to run the following code to learn how to use the min and max attribute in HTML.

<!DOCTYPE html>
<html>
   <head>
      <title>HTML min and max attribute</title>
   </head>
   <body>
      <form action = "" method = "get">
         Mention any number between 1 to 20
         <input type = "number" name="num" min = "1" max = "20"><br>
         <input type = "submit" value = "Submit">
      </form>
   </body>
</html>