Skip to main content

HTML Guide

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

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="">

Learn more:

Related W3C validator issues