References

Beginner-friendly references for web development, with live, editable examples.

The HTML max attribute

Attribute All modern browsers
In short

The HTML max attribute sets the upper limit of a number, date, time or range input. With max="6" on a number field, a larger value fails validation and the form won't submit. A range slider moves a larger value back to max instead.

Overview

The HTML max attribute sets the highest value a form control accepts. It works on <input> fields of type number, range, date, month, week, time and datetime-local. Text fields ignore it. Desktop Firefox and Safari don't support the month and week types.

A value above max fails constraint validation. The field's validity.rangeOverflow property turns true, the :invalid and :out-of-range pseudo-classes match, and the form won't submit. A value equal to max passes, and so does an empty field.

The format of max follows the input type. A number or range input takes a number such as 6 or 2.5, a date input a date such as 2026-12-31, and a time input a time such as 17:30. If max isn't in that format, the browser ignores it.

An ignored max leaves a number or date field with no upper limit, but a range slider falls back to 100, its default. As long as max is at or above min, a slider never reports an overflow. It moves a larger value down to max, or to the nearest step below max.

On <progress>, max is the total amount of work and must be above zero. On <meter>, it is the top of the gauge. Both use 1 when max is missing.

Syntax

<label for="qty">Tickets (1 to 6)</label>
<input type="number" id="qty" name="qty" min="1" max="6">

Values

Value
A number, or a date or time string in the input type's format.

Example

Live example
<form id="booking">
  <p>
    <label for="qty">Tickets (1 to 6)</label>
    <input type="number" id="qty" name="qty" min="1" max="6" value="7">
  </p>
  <p>
    <label for="day">Date (before 2027)</label>
    <input type="date" id="day" name="day" max="2026-12-31">
  </p>
  <button>Check</button>
  <p id="msg" role="status"></p>
  <p>Press Check, then change Tickets to 6 and press it again.</p>
</form>
<script>
const form = document.getElementById('booking');
const msg = document.getElementById('msg');
form.addEventListener('invalid', function (e) {
  if (e.target === form.querySelector(':invalid')) {
    msg.textContent = e.target.labels[0].textContent + ': ' + e.target.validationMessage;
  }
}, true);
form.addEventListener('submit', function (e) {
  e.preventDefault();
  msg.textContent = 'No value is above its max.';
});
</script>

Best practices

  • Write a date max as year-month-day, such as 2026-12-31. Written as 12/31/2026, the same max is invalid and the field gets no upper limit.
  • Keep max at or above min on number and date inputs.
  • Choose a max you can reach from min in whole steps, such as min="1", step="3" and max="10". When max falls between step values, stepUp() stops at the last step below it, and in Chrome the arrow keys do too.
  • Repeat the upper-limit check on the server. Anyone can delete the max attribute in developer tools or send the request without the form.

Accessibility

State the max value before people start typing, as in "Tickets (1 to 6)". A note inside the <label> may be enough, or you can tie a separate hint to the field with aria-describedby. Otherwise people may learn the limit only from the error after the form fails to submit.

Frequently asked questions

What does the max attribute do in HTML?
The max attribute sets the highest value an input accepts. On a number or date field, a larger value makes the field invalid and keeps the form from submitting.
Does the max attribute limit how many characters a field takes?
No, max limits a value such as a number or a date, not its length. Use the maxlength attribute to cap the number of characters in a text field.
How do I set max on a date input?
Set max to a year-month-day date such as 2026-12-31. Month, week and datetime-local inputs take forms such as 2026-12, 2026-W52 and 2026-12-31T17:30.
Why can I type a number above max?
The max attribute doesn't block typing. In Chrome, you can type 25 into a field whose max is 10, but the field turns invalid and the form won't submit.
Can max be lower than min?
Yes, a time input accepts max below min, since a range such as 21:00 to 06:00 wraps past midnight. On number and date inputs, a max below min makes every value invalid.
What is the default max of a range input?
A range input uses 100 as its max when the attribute is missing or can't be read. Its slider stops at max, so a range field whose max is at or above min never fails validation for a value that is too high.