html tutorial - step Attribute in HTML - html5 - html code - html form



Step attribute in html

Learn html - html tutorial - Step attribute in html - html examples - html programs

  • The step attribute defines the legal number intervals for an <input> tag.
  • For example if step=5, the legal number intervals could be -5, 0, 5, 10, 15, etc.

Syntax for step attribute in HTML:

<input step="number">

Differences between HTML 4.01 and HTML5 for step attribute:

HTML 4.01

  • HTML4 does not support step attribute.

HTML 5

  • The step attribute is new in HTML5.

Applies To:

Element Attribute
<input> step

Attribute Values:

Value Description
number Describes the legal number intervals for an input field.

Sample Coding for step Attribute in HTML:

Tryit<!DOCTYPE html>
<html>
   <head>
    <title>Wikitechy step attribute</title>
   </head>
   <body>
    <form action="step.html">
    <input type="number" name="point" step="5">
    <input type="submit">
    </form>
  </body>
</html>

Code Explanation for step Attribute in HTML:

step Attribute Code Explanation

  1. <form> tag is used to design a form for user input.
  2. <input> tag is used to getting the number from the user.
  3. type attribute defines the type of element (The value is number)
  4. name attribute defines the name of the element.
  5. step attribute describes the legal number intervals for an input field.

Output for step Attribute in HTML:

step Attribute Tag Output

  1. The output shows that, if input as 9 then the step attribute displays a warning message as “please enter a valid value. The two nearest valid values are 5 and 10".
step Attribute Tag Output

  1. If input as 15 the step attribute accepts that value because 15 is a multiplication of step value 5.After click the submit button the result is shows in URL as point=15, because the form has been submitted.

Browser Support for step Attribute in HTML:

6.0 10.0 16.0 5.0 10.6

Tips and Notes

  • The step attribute may be used together with the max and min attributes to create a range of legal values.
  • The step attribute works with the following input types: number, range, date, datetime, datetime-local, month, time and week.

Related Searches to step Attribute in html