Skip to main content

HTML Guide

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

The for attribute on a label element can’t be an empty string. This attribute is intended to specify which form element a label is associated with, and it must reference the ID of an existing form element. An empty string is neither a valid ID nor a meaningful association.

Explanation

  • Invalid HTML: <label for=""></label>

The for attribute expects the value to be the ID of a form element, such as an input, textarea, select, etc.

How to Fix

  1. Identify the Form Element: Find the form element (input, textarea, select, etc.) that the label is supposed to be associated with.
  2. Assign an ID to the Form Element: Ensure the form element has a unique ID.
  3. Modify the Label’s for Attribute: Set the for attribute of the label to match the ID of the form element.

Example

Before Fix

<form>
    <label for="">Username:</label>
    <input type="text" name="username">
</form>

After Fix

<form>
    <label for="username">Username:</label>
    <input type="text" id="username" name="username">
</form>

Learn more:

Related W3C validator issues