HTML Numeric Validation: Min, Max and Step
Check lower and upper bounds
min and max establish inclusive bounds for applicable numeric and temporal controls. A value below min causes rangeUnderflow; above max causes rangeOverflow. The browser can still allow typing an invalid number.
<label> Seats <input type="number" min="1" max="6" value="8"></label>8 exceeds the maximum; 6 is valid.
Predict the step grid
For number inputs the step base is min if present, otherwise a valid value attribute, otherwise zero. With min=0.2 and step=0.5, the grid contains 0.2, 0.7, 1.2 and so on. A value may be inside the bounds yet fail the step constraint.
<label> Weight <input type="number" min="0.2" max="3" step="0.5" value="1"></label>1 triggers stepMismatch; 1.2 is valid.
Allow arbitrary increments
step="any" removes the step constraint but preserves min and max. Empty number fields are valid unless required; an invalid typed number can produce badInput, which is different from an empty value.
<label> Temperature <input type="number" min="0" max="50" step="any" value="12.34"></label>12.34 passes; -1 is below the minimum.
Common mistakes and practice
For dates and times, step units differ by input type. A range slider normalizes its value; a number field may retain an out-of-range value. Validate real quantities against server-side business rules as well.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
HTML Numeric Validation: Min, Max and Step — Knowledge Check
Apply the control concepts taught in this lesson.
Which flag indicates a value above max?
With min=0.2 and step=0.5, which is valid?
For this number field, which constraint still rejects the value 55?
<input type="number" min="0" max="50" step="any" value="55">What is the effect of an empty optional number field?
Which control may keep an out-of-range typed value?