Skip to main content

HTML Guide

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

Remove the empty maxlength and provide a valid non‑negative integer, or omit maxlength entirely.

The maxlength attribute limits the number of characters a user can enter. It must be a valid non-negative integer (0, 1, 2, …). An empty string, whitespace, or non-numeric value fails validation. When maxlength is omitted, the length is unlimited. When set to 0, no characters can be entered. The value applies to the textarea element itself, not its content.

Common fixes:

  • Set maxlength to a concrete number like 200.
  • If you don’t need a limit, remove the attribute.
  • Ensure templating doesn’t output an empty attribute (e.g., maxlength="").

HTML Examples

Invalid example (reproduces the validator error)

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Invalid maxlength</title>
</head>
<body>
  <form>
    <label for="msg">Message</label>
    <textarea id="msg" name="message" maxlength=""></textarea>
  </form>
</body>
</html>

Fixed example (valid integer or omit attribute)

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Valid maxlength</title>
</head>
<body>
  <form>
    <label for="msg">Message (max 200 chars)</label>
    <textarea id="msg" name="message" maxlength="200"></textarea>
  </form>
</body>
</html>

Learn more:

Related W3C validator issues