HTML max Attribute

Beginner
⏱️ 6 min read
📚 Updated: Jun 2026
🎯 3 Examples
Forms & Input

Introduction

The max attribute sets the maximum allowed value on certain <input> types and defines the upper bound of the scale on <meter> and <progress> elements. It is essential for form validation—capping quantities, limiting date pickers, and constraining range sliders. Pair it with min to define a valid range. Do not confuse max with maxlength (character count on text inputs) or high on <meter> (warning threshold, not the scale limit).

What You’ll Learn

01

Upper limit

Cap user input.

02

number & range

Numeric max value.

03

date & time

ISO-style strings.

04

With min

Valid range pair.

05

vs maxlength

Value vs characters.

06

input.max

Update in JS.

Purpose of max Attribute

The primary purpose of the max attribute is to define the highest value a user may enter or select. On a number field, it prevents quantities above a business rule (e.g. stock on hand). On a date field, it blocks dates after a deadline. On a range slider, it sets the right end of the track.

Browsers use max (with min and step) for constraint validation. When the value exceeds max, the input is invalid and :invalid styling or checkValidity() reflects the error. This improves UX but must be repeated on the server for security.

💡
Not the same as maxlength or meter high

maxlength limits how many characters can be typed in text inputs. high on <meter> marks a warning zone on a gauge—it does not cap user input. max on <input type="number"> sets the numeric upper bound for form validation.

📝 Syntax

Add max to supported input types (often with min):

max.html
<label for="qty">Quantity:</label>
<input type="number" id="qty" min="1" max="100">

<label for="eventDate">Event date:</label>
<input type="date" id="eventDate" max="2025-12-31">

<label for="closing">Closing time:</label>
<input type="time" id="closing" max="18:00">

<input type="range" min="0" max="500" value="250">

Syntax Rules

  • Value format depends on type: number/range use numeric strings; date uses YYYY-MM-DD; time uses HH:MM or HH:MM:SS.
  • datetime-local uses YYYY-MM-DDTHH:MM (e.g. 2025-12-31T23:59).
  • Ensure min ≤ max when both are set.
  • On <meter> and <progress>, max defines the scale upper bound (default often 1 or 100).
  • Not valid on type="text", checkbox, radio, etc.—use maxlength for text length.
  • JavaScript: input.max = "100" (string) on HTMLInputElement.

💎 Values

The max attribute accepts a string whose format matches the control type:

  • Number / rangemax="100", max="3.5" (valid floating-point string).
  • Datemax="2025-12-31" (YYYY-MM-DD).
  • Timemax="18:00" or max="18:00:00".
  • Datetime-localmax="2025-12-31T23:59".
  • Monthmax="2025-12"; Weekmax="2025-W52".
  • Meter / progressmax="100" sets the top of the scale (meter also uses high for warning zones).
max-js.html
document.getElementById("ticketPrice").max = "500";
document.getElementById("dynamicMaxField").setAttribute("max", "1000");

⚡ Quick Reference

Input typeExample maxFormat
numbermax="100"Numeric string
rangemax="500"Slider upper bound
datemax="2025-12-31"YYYY-MM-DD
timemax="18:00"HH:MM
datetime-localmax="2025-12-31T23:59"ISO local datetime
textUse maxlengthNot max

Applicable Elements

Element / typeSupported?Notes
<input type="number">YesPrimary use case
<input type="range">YesSlider maximum
<input type="date">, time, datetime-localYesLatest selectable value
<input type="month">, weekYesType-specific string format
<meter>, <progress>YesScale upper bound
<input type="text">NoUse maxlength instead

max vs min vs maxlength vs meter high

AttributeApplies toPurpose
maxnumber, range, date/time inputs; meter, progressMaximum allowed value or scale bound
minSame input types; meter, progressMinimum allowed value or scale bound
maxlengthtext, search, url, tel, email, passwordMaximum character count
high<meter> onlyWarning threshold on gauge (not form limit)

Examples Gallery

Number input cap, date deadline, and dynamic max on a range slider with JavaScript.

👀 Live Preview

Quantity field with min="1" and max="100":

Values above 100 fail browser constraint validation when the form is submitted or checkValidity() runs.

Example — Number Input Upper Limit

Cap ticket quantity or price with max on a number field:

number-max.html
<label for="ticketPrice">Ticket price ($):</label>
<input
  type="number"
  id="ticketPrice"
  name="ticketPrice"
  min="0"
  max="500"
  step="0.01">
Try It Yourself

How It Works

The browser compares the current value to max during constraint validation. Invalid values block form submission unless JavaScript bypasses checks—another reason to validate on the server.

Example — Form with Date and Number max

Combine date and number limits in one form:

form-max.html
<form>
  <label for="eventDate">Event date:</label>
  <input type="date" id="eventDate" max="2025-12-31">

  <label for="ticketPrice">Ticket price:</label>
  <input type="number" id="ticketPrice" max="500">

  <button type="submit">Submit</button>
</form>
Try It Yourself

How It Works

Each input type interprets max in its own format. The event date cannot exceed the end of 2025; ticket price cannot exceed 500. Both use the same attribute name with type-specific values.

Dynamic Values with JavaScript

Adjust the maximum at runtime when business rules change:

dynamic-max.html
<input type="range" id="price" min="0" max="500" value="250">

<script>
  document.getElementById("price").max = "1000";
</script>
Try It Yourself

How It Works

Assigning a string to input.max updates the upper bound immediately. The range slider thumb can move further right after the limit increases. Re-validate the current value if the new max is lower than what the user already entered.

♿ Accessibility

  • Pair labels with inputs — Use <label for="id"> so users know what the max limit applies to.
  • Describe limits in help text — State the allowed range visibly (e.g. “1–100”) for screen reader users and sighted users alike.
  • Do not rely on color alone — Invalid states should include text or aria-invalid when you enhance validation with JavaScript.
  • Announce dynamic max changes — If JavaScript lowers max, consider an aria-live region explaining the new limit.
  • Server validation for everyone — Assistive technology users deserve the same enforced limits as sighted users; client max alone is insufficient.

🧠 How max Works

1

Author sets max

Upper bound in markup.

Markup
2

User enters value

Type, pick, or slide.

Input
3

Constraint validation

value ≤ max required.

Validate
=

Valid submission

Or :invalid if over max.

Browser Support

The max attribute is fully supported on all listed input types, <meter>, and <progress> in modern browsers. Validation behavior is consistent across Chrome, Firefox, Safari, and Edge.

HTML5 · Fully supported

Reliable form upper limits

All major browsers honor max on number, range, and date/time inputs.

98% Browser support
Google Chrome Fully supported
Full support
Mozilla Firefox Fully supported
Full support
Apple Safari Fully supported
Full support
Microsoft Edge Fully supported
Full support
max on form inputs 98% supported

Bottom line: Safe to use on supported input types; always validate on the server too.

💡 Best Practices

✅ Do

  • Pair max with min for clear valid ranges
  • Use type-appropriate value formats (dates, times, numbers)
  • Show the allowed range in visible label or help text
  • Validate again on the server before saving data
  • Update max in JS when dynamic limits apply

❌ Don’t

  • Use max on text inputs (use maxlength)
  • Confuse max with meter high warning thresholds
  • Trust client-side max alone for security
  • Set min greater than max
  • Forget step when fractional numbers matter

Conclusion

The max attribute is a valuable tool for defining upper limits on user input in HTML forms. Whether you are capping quantities, limiting date pickers, or setting range slider bounds, max works with browser constraint validation to guide users toward valid data.

Remember to pair it with min, distinguish it from maxlength, and always enforce limits on the server. Used thoughtfully, max improves accuracy and the overall form experience.

Key Takeaways

Knowledge Unlocked

Five truths every developer should know about max

Bookmark these before building your next form.

5
Core concepts
📅 02

date/time/number

Type-specific format.

Syntax
📝 03

vs maxlength

Value vs chars.

Compare
⚙️ 04

With min

Define valid range.

Pair
🔒 05

Server too

Client max ≠ secure.

Security

❓ Frequently Asked Questions

It sets the maximum allowed value on supported <input> types and the upper bound of the scale on <meter> and <progress>. Values above max fail constraint validation.
No. max limits numeric or date/time values on specific input types. maxlength limits how many characters can be typed in text-like inputs.
number, range, date, time, datetime-local, month, and week. Text inputs use maxlength instead.
Use inputElement.max = "100" or setAttribute("max", "100"). The value is a string matching the input type’s expected format.
Yes. Together they define the valid range. For example min="1" max="100" on a quantity field. Ensure min ≤ max.
No. max is client-side constraint validation only. Attackers can bypass it. Always enforce upper limits on the server.

Cap form values with max

Practice the max attribute on number, date, and range inputs in the Try It editor.

Try number input example →

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.

5 people found this page helpful