Skip to main content
HTML Validation

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

About This HTML Issue

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>

Last reviewed: September 19, 2024

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.