Skip to main content
HTML Validation

Bad value “” for attribute “maxlength” on element “input”: The empty string is not a valid non-negative integer.

About This HTML Issue

Remove the empty maxlength value and provide a non-negative integer or omit the attribute entirely.

Explanation

The maxlength attribute on an input element must be a valid non-negative integer per the HTML specification. An empty string ("") is invalid and triggers the validator error.

  • Valid: a decimal integer like 0, 10, 255.
  • Invalid: empty string, negative numbers, non-numeric strings, or whitespace.
    If no maximum length is needed, omit maxlength instead of leaving it empty.
    Note that maxlength applies to text-entry controls such as type="text", search, url, tel, email, and password. For other types (e.g., number, date), maxlength is ignored and should not be used.

Examples

Correct: set an explicit maximum

<input type="text" name="username" maxlength="20">

Correct: no maximum, omit the attribute

<input type="text" name="comment">

Incorrect: empty string (validator error)

<input type="text" name="username" maxlength="">

Last reviewed: August 11, 2025

Was this guide helpful?

Find issues like this automatically

Rocket Validator scans thousands of pages in seconds, detecting HTML issues across your entire site.

Ready to validate your sites?
Start your free trial today.