HTML reference
input min and max
The min and max attributes describe the smallest and largest allowed value for supported inputs such as numbers, dates, and times.
What you will learn
- What range
minandmaxdescribe - How
stepaffects valid values - Why browser validation does not replace server validation
Typing an out-of-range number does not mean the rule failed
min and max define the range of valid values. A browser may let you type a number outside that range but still mark it invalid. Normal form submission checks validity and blocks invalid values.
<form>
<label for="quantity">Quantity (1–10)</label>
<input id="quantity" name="quantity" type="number"
min="1" max="10" step="1" required>
<button type="submit">Check quantity</button>
</form>
Compare values and validity
Actual value: 1
valueMissing: false rangeUnderflow: false rangeOverflow: false stepMismatch: false
1 meets the rules. No data is sent.
| Flag | When it is true |
|---|---|
valueMissing | The field is required and empty |
rangeUnderflow | The value is below min |
rangeOverflow | The value is above max |
stepMismatch | The value does not match the step, such as 1.5 here |
Try 11. Then clear the field and uncheck required. Range constraints and requiring a value do different jobs. The demo checks the form and shows the result without sending data.
What to check when the result is unexpected
- Use minlength and maxlength for text length. min and max do not set a character count.
- Choose an appropriate step for decimals. For example, step="0.5" allows half-unit steps from the step base.
- form.submit() bypasses browser constraint validation. See the button article for how this differs from a submit button or requestSubmit().
- Browser checks can be bypassed. Check the range and step on the server too.
Source: HTML constraint validation.
Basic example
<label for="age">Age</label>
<input id="age" name="age" type="number" min="0" max="120" step="1">A value below min or above max is invalid for constraint validation. The attributes guide the browser UI, but they do not make untrusted input safe.
Combining with step
<input type="number" min="0" max="10" step="0.5">Here, values such as 0, 0.5, and 1 are valid points in the range. Check the input type's rules and choose a step that matches the unit users understand.
Dates and times
<input type="date" min="2026-01-01" max="2026-12-31">Date and time values use their documented machine-readable formats. Test the experience in the browsers and locales your users rely on.
Server-side validation
Users can send requests without your form, and browsers can be bypassed. Validate the range again on the server before storing data or performing an action.