How to use step attribute in HTML?


The HTML input type step attribute sets the legal number intervals. Steps are number steps like 0, 4, 8, 12, 16, etc. The step attribute can be used together with the max and min attributes to create a range of legal values.

Example

You can try to run the following code to create a step of numbers with the input step attribute. Here, we are creating a step 4, so the valid input will be 4, 8, 12, 16, etc. On entering a number except that and pressing submit button, the following message will be visible: “Please enter a valid value”. It will also let you know the two nearest values.

<!DOCTYPE html>
<html>
   <head>
      <title>HTML input step attribute</title>
   </head>
   <body>
     <form action = "/cgi-bin/hello_get.cgi" method = "get">
        <input type = "number" name = "points" step = "4"><br>
        <input type = "submit" value = "Submit">
     </form>
   </body>
</html>

Updated on: 14-May-2020

168 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements