HTML Guides for max
Learn how to identify and fix common HTML validation errors flagged by the W3C Validator — so your pages are standards-compliant and render correctly across every browser. Also check our Accessibility Guides.
The max attribute defines the maximum value that is acceptable and valid for the input containing it. When the browser encounters max="", it expects a valid floating-point number as defined by the HTML specification. An empty string cannot be parsed as a number, so the attribute becomes meaningless and triggers a validation error.
This commonly happens when HTML is generated dynamically by a template engine or framework that outputs an empty value for max when no maximum has been configured. It can also occur when a developer adds the attribute as a placeholder intending to fill it in later.
While most browsers will silently ignore an invalid max value, relying on this behavior is problematic for several reasons:
- Standards compliance: The HTML specification requires
maxto be a valid floating-point number when present. - Predictable validation: An empty
maxmeans no client-side maximum constraint is enforced, which may not be the developer's intent. Explicitly removing the attribute makes that intention clear. - Accessibility: Assistive technologies may read the
maxattribute to communicate input constraints to users. An empty value could lead to confusing or undefined behavior.
This error applies to input types that accept numeric-style max values, including number, range, date, datetime-local, month, week, and time.
How to Fix It
- Set a valid numeric value: If you need a maximum constraint, provide a proper floating-point number (e.g.,
max="100"ormax="99.5"). - Remove the attribute: If no maximum is needed, remove the
maxattribute entirely rather than leaving it empty. - Fix dynamic templates: If your HTML is generated from a template, add a conditional check so that
maxis only rendered when a value is actually available.
Examples
❌ Invalid: Empty max attribute
<labelfor="quantity">Quantity:</label>
<inputtype="number"id="quantity"name="quantity"max="">
The empty string "" is not a valid floating-point number, so this triggers the validation error.
✅ Fixed: Providing a valid numeric value
<labelfor="quantity">Quantity:</label>
<inputtype="number"id="quantity"name="quantity"max="100">
✅ Fixed: Removing the attribute entirely
<labelfor="quantity">Quantity:</label>
<inputtype="number"id="quantity"name="quantity">
If no maximum constraint is needed, simply omit the max attribute.
❌ Invalid: Empty max on a date input
<labelfor="end-date">End date:</label>
<inputtype="date"id="end-date"name="end-date"max="">
✅ Fixed: Valid date value for max
<labelfor="end-date">End date:</label>
<inputtype="date"id="end-date"name="end-date"max="2025-12-31">
For date-related input types, the max value must be in the appropriate date/time format (e.g., YYYY-MM-DD for type="date").
Fixing dynamic templates
If you're generating HTML with a templating language, conditionally include the attribute only when a value exists. For example, in a Jinja2-style template:
<inputtype="number"id="price"name="price"
{%ifmax_price%}max="{{ max_price }}"{%endif%}>
This ensures the max attribute is only rendered when max_price has a valid value, avoiding the empty-string problem entirely.
Validate at scale.
Ship accessible websites, faster.
Automated HTML & accessibility validation for large sites. Check thousands of pages against WCAG guidelines and W3C standards in minutes, not days.
Pro Trial
Full Pro access. Cancel anytime.
Start Pro Trial →Join teams across 40+ countries