Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / HTML

step — allowed-value increments for input

The step attribute sets the spacing between allowed numeric or date/time values in an input. Steps are measured from a base; any removes this constraint without removing other validity rules.

Version: WHATWG HTML Living Standard; index snapshot date recorded separately

Syntax

step="<positive floating-point number>" | step="any"

step applies to number, range, date, month, week, time, and datetime-local. In conforming HTML, the attribute value must be a valid floating-point number greater than zero or any (ASCII case-insensitive). If the attribute is absent, the default step applies. If the value is not any, the browser parses it as a floating-point number and uses the default step only if parsing fails or yields zero or a negative number. For example, step="2px" is nonconforming, but it can parse as 2 and set the step to 2.

The base is, in priority order: a valid min attribute, a valid value content attribute, the type's default base, or zero. Changing the .value property does not change the value content attribute. The difference between the value and base must be an integer multiple of the unit-scaled step; otherwise validity.stepMismatch is true.

The default step is 1 for number and range, 1 day for date, 1 month for month, 1 week for week, and 60 seconds for time and datetime-local. The exceptional week base is the Monday starting 1970-W01, or −259200000 milliseconds relative to the Unix epoch.

step="any" removes only the step constraint: it does not remove min, max, or format requirements. With any, stepUp() and stepDown() throw InvalidStateError. The example tests step alignment, not overall field validity.

Examples

const input = document.createElement('input');
input.type = 'number';
input.min = '0.5';
input.step = '0.25';

input.value = '1';
console.log(input.validity.stepMismatch);
input.value = '1.1';
console.log(input.validity.stepMismatch);
input.step = 'any';
console.log(input.validity.stepMismatch);

Result

false
true
false

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources