HTML: input type="number"
The number input is useful for numeric values and can describe a range and increment with min, max, and step.
What you will learn
- How to label a numeric field
- How range and increment constraints work
- Why browser constraints are not a security boundary
Minimal example
<label for="guests">Guests</label>
<input id="guests" name="guests" type="number"
min="1" max="12" step="1" value="2" required>The browser can offer number controls and report values outside the declared range. The server must still parse and validate the submitted value.
Common mistakes
- Use
step="any"or a suitable decimal step when fractions are valid. - Do not use number input for identifiers that may contain leading zeroes; use text instead.
- Keep a visible label and explain units, such as minutes or kilograms, in the label or nearby text.