HTML - step Attribute



The step attribute is an HTML attribute used to set the interval between legal numbers or the distinct step size of the <input> tag.

The step sets the stepping interval when clicking up and down spinner buttons, moving a slider left and right on a range, and validating the different data types. If not explicitly included, then the default value is set to 1 for number and range.

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

The default stepping value for time is 1 second, with 900 begin equal to 15 minutes.

For example; if step = "3", legal number could be -3, 0, 3, 6, etc.

Syntax

Following is the syntax of the step attribute −

<input step = "value" >

Example

In the following example, we are using the step attribute in the input tag to increase or decrease the number by 5.

<!DOCTYPE html>
<html>
<head>
   <title>HTML step Attribute</title>
   <style>
      body {
         text-align: center;
      }
   </style>
</head>
<body>
   <h1 style="color: green;">tutorials <span style="color: black">point</span>
   </h1>
   <h2>HTML step Attribute</h2>
   <input type="number" name="tp" step="5" placeholder="multiples of 5">
</body>
</html>

When we run the above code, it will generate an output consisting of the input field mentioned with step attribute displayed on the webpage.when the user tries to increases or decreases the value it give multiples of 5.

Example

Considering the another scenario, where we are going to use the step attribute by 2 on the input type=month.

<!DOCTYPE html>
<html>
<head>
   <title>HTML step Attribute</title>
   <style>
      body {
         text-align: center;
      }
   </style>
</head>
<body>
   <h1 style="color: green;">tutorials <span style="color: black">point</span>
   </h1>
   <h2>HTML step Attribute</h2>
   <input type="month" name="month" step="2" placeholder="month will step by 2">
</body>
</html>

On running the above code, the output window will pop up displaying the input field applied with step attribute on the webpage.

Example

Let's look into the following example, where we are going to use the step attribute by 10 with the input type=range.

<!DOCTYPE html>
<html>
<head>
   <title>HTML step Attribute</title>
   <style>
      body {
         text-align: center;
      }
   </style>
</head>
<body>
   <h1 style="color: green;">tutorials <span style="color: black">point</span>
   </h1>
   <h2>HTML step Attribute</h2>
   <input type="range" name="range" step="10">
</body>
</html>

When we run the above code, the output window will pop up displaying the range meter mentioned with step attribute displayed on the webpage.

html_attributes_reference.htm
Advertisements