Skip to main content

HTML Guide

Bad value “” for attribute “name” on element “a”: An ID must not be the empty string.

Empty name attributes on <a> are invalid; an anchor’s name/id must be a non-empty unique identifier.

Historically, the name attribute on <a> was used to create fragment targets (e.g., <a name="top"></a>). In HTML5/living standard, fragment navigation should use the id attribute instead. The name attribute on <a> is obsolete for this purpose, and an empty string is never allowed for identifiers.

Use id with a non-empty value to create link targets, and point to them with href="#idValue". If you keep name for legacy reasons, it must still be non-empty and match the HTML syntax for valid IDs. Avoid adding empty attributes like name="" or id="". Also ensure uniqueness of each id in the document.

HTML Examples

Example causing the validator error

<!doctype html>
<html lang="en">
  <head>
    <title>Anchor name error</title>
  </head>
  <body>
    <a name=""></a>
    <a href="#"></a>
  </body>
</html>

Corrected example using id (recommended)

<!doctype html>
<html lang="en">
  <head>
    <title>Anchor id fix</title>
  </head>
  <body>
    <a id="top"></a>
    <a href="#top">Back to top</a>
  </body>
</html>

Learn more:

Related W3C validator issues