<input max="">
- Attribute of
- How To Use Input To Create Form Fields In HTML: Easy Tutorial
- What does
<input max="">
do? - Specifies a maximum value for number and date input fields.
Code Example
<form>
<label for="hours">How many hours are you available to work each week?</label><br>
<input type="number" id="hours" name="hours" max="168">
</form>
<!-- Try putting in 170 and pressing enter. -->
The max
attribute and data validation
Specifying a max
attribute on an <input>
element allows you to put an upper limit on certain types of inputs ‘number’ and ‘date’. The form will not accept any inputs higher than the max
value. However, that does not absolve you (the developer) of proper form validation. For one thing, a browser that doesn’t support the max
attribute will still allow a user to enter an invalidly high value. More importantly, though, it is (almost) always possible for a malicious user to submit data to your server directly, bypassing the HTML form altogether. (This can happen for any form field.) So, using the max
attribute to limit the value of numerical or date-based inputs can help usability a little bit, but don’t rely on it if a too-high value would cause problems on when submitted to the server.
Browser Support for max
![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
10 | 43 | 45 | 13 | 9 | 34 |