Skip to content
Related Articles

Related Articles

How to specify the legal number intervals for an input field in HTML5 ?

View Discussion
Improve Article
Save Article
  • Last Updated : 17 Mar, 2021

In this article, we learn how to set the legal number intervals in the input field. This helps the user to enter numbers that follow the given interval and disallows any other value during validation. 

We have to use the step attribute of the <input> element to set up the legal intervals in the input field. We will first create a form that contains the input area and set its step attribute to the value required. The validation of the field would automatically take place when the user tries to submit the form by showing an error.


<input type="number" step="value">

Example: In this example, the step attribute is set to 4, therefore a user is allowed to enter values that are in steps of 4.


    <h1 style="color: green">
    <form action="/">
        <label for="score">
        <input type="number" name="score"
               id="score" step="4">
        <button type="submit">


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!