Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

How to use input type field with steps in HTML?

I need to work on the step attribute of form input type to create a range of numbers. For my website, I want to show a range of steps. How can I use input type field with steps in HTML?


1 Answer
Samual Sam

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

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 5, so the valid input will be 5, 10, 15, 20, 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 = "" method = "get">
         <input type="number" name="points" step="5"><br>
         <input type="submit" value="Submit">
      </form>
   </body>
</html>
Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.