# Bad value “” for attribute “max” on element “input”: The empty string is not a valid floating point number.

> Canonical HTML version: https://rocketvalidator.com/html-validation/bad-value-for-attribute-max-on-element-input-the-empty-string-is-not-a-valid-floating-point-number
> Attribution: Rocket Validator (https://rocketvalidator.com)
> License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)

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 `max` to be a valid floating-point number when present.
- **Predictable validation**: An empty `max` means 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 `max` attribute 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

1. **Set a valid numeric value**: If you need a maximum constraint, provide a proper floating-point number (e.g., `max="100"` or `max="99.5"`).
2. **Remove the attribute**: If no maximum is needed, remove the `max` attribute entirely rather than leaving it empty.
3. **Fix dynamic templates**: If your HTML is generated from a template, add a conditional check so that `max` is only rendered when a value is actually available.

## Examples

### ❌ Invalid: Empty `max` attribute

```html
<label for="quantity">Quantity:</label>
<input type="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

```html
<label for="quantity">Quantity:</label>
<input type="number" id="quantity" name="quantity" max="100">
```

### ✅ Fixed: Removing the attribute entirely

```html
<label for="quantity">Quantity:</label>
<input type="number" id="quantity" name="quantity">
```

If no maximum constraint is needed, simply omit the `max` attribute.

### ❌ Invalid: Empty `max` on a date input

```html
<label for="end-date">End date:</label>
<input type="date" id="end-date" name="end-date" max="">
```

### ✅ Fixed: Valid date value for `max`

```html
<label for="end-date">End date:</label>
<input type="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:

```html
<input type="number" id="price" name="price"
  {% if max_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.
