HTML <input type="number">
Example
Define a field for entering a number (You can also set restrictions on what numbers are accepted):
<label for="quantity">Quantity (between 1 and 5):</label>
<input type="number"
id="quantity" name="quantity" min="1" max="5">
Try it Yourself »
Definition and Usage
The <input type="number">
defines a field for entering a number.
Use the following attributes to specify restrictions:
- max - specifies the maximum value allowed
- min - specifies the minimum value allowed
- step - specifies the legal number intervals
- value - Specifies the default value
Tip: Always add the <label>
tag
for best accessibility practices!
Browser Support
Attribute | |||||
---|---|---|---|---|---|
type="number" | Yes | Yes | Yes | Yes | Yes |
Syntax
<input type="number">