HTMLInputElement.stepDown()

The HTMLInputElement.stepDown([n]) method decrements the value of a numeric type of <input> element by the value of the step attribute or up to n multiples of the step attribute if a number is passed as the parameter. The method, when invoked, decrements the value by (step * n), where n defaults to 1 if not specified, and step defaults to the default value for step if not specified.

Valid on all numeric, date, and time input types that support the step attribute, includingdate, month, week, time, datetime-local, number, and range.

Given <input id="myTime" type="time" max="17:00" step="900" value="17:00">, invoking myTime.step(3) will change the value to 16:15, decrementing the time by 3 * 900, or 45 minutes. myTime.step(), with no parameter, would have resulted in 16:45, as n defaults to 1.

<!--  decrements by intervals of 900 seconds (15 minute) -->
<input type="time" max="17:00" step="900">

<!-- decrements by intervals of 7 days (one week) -->
<input type="date" max="2019-12-25" step="7">

<!-- decrements by intervals of 12 months (one year) -->
<input type="month" max="2019-12" step="12">

The method, when invoked, changes the form control's value by the value given in the step attribute, multiplied by the parameter, within the constraints set within the form control. The default value for the parameter, if not is passed, is 1. The method will not cause the value to go below the min value set or defy the constraints set by the step attribute. A negative value for n will increment the value, but will not increment beyond the max value.

If the value before invoking the stepDown() method is invalid, for example, if it doesn't match the constraints set by the step attribute, invoking the stepDown() method will return a value that does match the form controls constraints.

If the form control is non time, date, or numeric in nature, and therefore does not support the step attribute (see the list of supported input types in the the table above), or if the step value is set to any, an InvalidStateError exception is thrown.

HTMLInputElement.stepDown()
Decrements the value by (step * n), where n defaults to 1 if not specified. Throws an INVALID_STATE_ERR exception:
  • if the method is not applicable to for the current type value,
  • if the element has no step value,
  • if the value cannot be converted to a number,
  • if the resulting value is above the max or below the min.

Syntax

element.stepDown( [ stepDecrement ] );

Parameters

stepDecrement
The optional stepDecrement paremeter is a numeric value. If no parameter is passed, stepDecrement defaults to 1.
If the value is a float, the value will increment as if Math.floor(stepDecrement) was passed. If the value is negative, the value will be incremented instead of decremented.

Example

Click the button in this example to increment the number input type:

HTML

<p>
  <label>Enter a number between 0 and 400 that is divisible by 5:
   <input type="number" step="5" id="theNumber" min="0" max="400">
  </label>
</p>
<p>
  <label>Enter how many values of step you would like to increment by or leave it blank:
   <input type="number" step="1" id="decrementer" min="-2" max="15">
  </label>
</p>
<input type="button" value="Decrement" id="theButton">

JavaScript

/* make the button call the function */
let button = document.getElementById('theButton');
button.addEventListener('click', function() {
  stepondown();}
);

function stepondown() {
  let input = document.getElementById('theNumber');
  let val = document.getElementById('decrementer').value;

  if (val) {  /* increment with a parameter */
    input.stepDown(val);
  } else {    /* or without a parameter. Try it with 0, 5, -2, etc. */
    input.stepDown();
  }
}

CSS

input:invalid {
  border: red solid 3px;
}

Result

Note if you don't pass a parameter to the stepDown() method, it defaults to 1. Any other value is a multiplier of the step attribute value, which in this case is 5. If we pass 4 as the stepDecrement, the input will stepDown by 4 * 5, or 20. If the parameter is 0, the number will not be decremented. The stepDown() method will not allow the input to go out of range, in this case stopping when it reaches 0 and rounding down and floats that are passed as a parameter.

Try setting the step decrementer to 1.2. What happens when you invoke the method?

Try setting the value to 44, which is not valid. What happens when you invoke the method?

Specifications

Specification Status Comment
HTML Living Standard
The definition of 'stepDown()' in that specification.
Living Standard
HTML 5.1
The definition of 'stepDown()' in that specification.
Recommendation
HTML5
The definition of 'stepDown()' in that specification.
Recommendation Initial definition

Browser compatibility

DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
stepDownChrome Full support YesEdge Full support 12Firefox Full support 16
Notes Disabled
Full support 16
Notes Disabled
Notes Experimental, and without specific UI. There are still differences with the latest spec: bug 835773.
Disabled From version 16: this feature is behind the dom.experimental_forms preference (needs to be set to true). To change preferences in Firefox, visit about:config.
IE ? Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes

Legend

Full support
Full support
Compatibility unknown
Compatibility unknown
See implementation notes.
See implementation notes.
User must explicitly enable this feature.
User must explicitly enable this feature.

See also