How to use step attribute in HTML?

HTMLWeb DevelopmentFront End Technology

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>
raja
Published on 24-Jan-2018 08:11:22
Advertisements