HTML max Attribute

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The max attribute sets the highest allowed value for numeric and date-like <input> types. If the control’s value is greater than max, constraint validation fails.

It also defines the upper bound on <meter> and <progress>. Pair it with min (and often step). It is not the same as maxlength, which limits characters.

Baseline · Widely available.

Not deprecated and not experimental. Stable across modern browsers for supported input types, meter, and progress.

Client hint — still validate on the server.

Users can bypass browser checks. Always enforce the same upper limit in your backend.

HTML Syntax

syntax.html
<input max=" value">

Also: <meter max="…"> and <progress max="…">. The format of value depends on the control (number, date string, and so on). Keep max ≥ min.

Attribute Values

Common shapes of max by control:

ValueDescriptionTry it
NumberUpper limit for type="number" and rangeTry it
yyyy-mm-ddLatest allowed date for type="date"Try it
On meter / progressEnd of the scale (default 1 if omitted)Try it
Invalid / missingNo maximum applied for that inputTry it

Live Preview

Change max on a number input. The current value stays at 50 so you can see when it goes out of range.

Fixed: min="0" value="50". Values above max are invalid (rangeOverflow).

Number input

max="50" — value equals max (still valid).

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Number Input Upper Limit

Cap a quantity so values above 100 fail validation.

HTML
<label for="qty">Quantity (1–100):</label>
<input
  type="number"
  id="qty"
  name="qty"
  min="1"
  max="100"
  value="50">
Try It Yourself

How It Works

  1. max = 100. Anything above 100 is out of range.
  2. min = 1. Lower bound; keep max ≥ min.
  3. Validation. Too-high values set rangeOverflow and match :invalid.
  4. Label the control. Tell users the allowed range in the label or help text.

Example 2 — Date Deadline with max

Stop the picker from choosing dates after a deadline.

HTML
<label for="event">Event date (on or before 2026-12-31):</label>
<input
  type="date"
  id="event"
  name="event"
  max="2026-12-31">
Try It Yourself

How It Works

  1. Format. Date max uses yyyy-mm-dd.
  2. Deadline. Dates after 2026-12-31 are invalid.
  3. Other types. month, week, time, and datetime-local use their own max formats.
  4. UX. State the deadline in the label so the limit is clear.

Example 3 — max on Progress

On <progress>, max is the total amount of work; value is how much is done.

HTML
<label for="upload">Upload:</label>
<progress id="upload" max="100" value="40">40%</progress>
Try It Yourself

How It Works

  1. max = 100. Full task size (must be greater than zero).
  2. value = 40. Current progress toward that total.
  3. Default. If max is omitted on progress or meter, it defaults to 1.
  4. Fallback text. 40% inside the tag helps when the bar UI is unavailable.

Edge Cases & Pitfalls

Most mistakes come from mixing up max with maxlength or using the wrong value format.

not maxlength

max ≠ maxlength

max caps a value. maxlength caps typed characters on text controls.

order

Keep max ≥ min

If max is less than min, or the attribute is invalid, the maximum is not applied as intended.

format

Match the input type

Dates need yyyy-mm-dd; times need HH:mm; numbers need a numeric string. Wrong formats are ignored.

meter

max is not high

On <meter>, max ends the whole scale. high only starts the upper zone inside that scale.

server

Re-check on the server

Client-side max can be bypassed. Enforce the same limit when you process the form.

Browser Support

max is an HTML attribute for inputs, meter, and progress in the browser. It is not a Node.js, Deno, or Bun API.

✓ Baseline · Widely available

max

Widely supported on number, range, and date-like inputs, plus meter and progress. Chrome, Firefox, Safari, Edge, and Opera support constraint validation with max.

96% Global support (approx.)
Google Chrome All
Full support
Mozilla Firefox All
Full support
Apple Safari All
Full support
Microsoft Edge All
Full support
Opera All
Full support
Samsung Internet All
Full support
Internet Explorer Partial*
Partial*
max Widely supported

Bottom line: *Safe on modern browsers. Always validate max again on the server.

Key Takeaways

  • Role: highest allowed value (inputs) or end of scale (meter/progress).
  • Order: keep max ≥ min; use the format that matches the control type.
  • Not maxlength: characters vs numeric/date value — different jobs.
  • Validation: over-max → rangeOverflow; still check on the server.

One line: max is the ceiling for the value — tell users the limit and enforce it server-side too.

Frequently Asked Questions

It sets the highest allowed value for number, range, and date-like inputs, and the upper bound for meter and progress. On inputs, a value above max fails constraint validation (rangeOverflow).
input types number, range, date, month, week, time, and datetime-local, plus the meter and progress elements.
max limits a numeric or date value. maxlength limits how many characters you can type in text fields and textarea.
Yes. The max value must be greater than or equal to min. If max is missing or invalid, no maximum is applied for that control.
The control is invalid. validity.rangeOverflow is true, and the field matches :invalid and :out-of-range. The browser can block form submit until it is fixed.
If max is omitted on meter or progress, the default is 1.

Next: maxlength

Cap how many characters users can type.

maxlength tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful