htmlforms

Can I use multiple labels for a form element?


Would the following be a valid usage of the label element in HTML5?

<label for="select">Some text</label>
<select id="select">
   ...
</select>
<label for="select">...more text</label>

The HTML5 spec don't seem to have anything to say about it (edit: this has since been clarified in the spec).


Solution

  • You can have multiple labels that point to the same form control and it's legal.

    According to HTML 4 Documentation:

    The LABEL element may be used to attach information to controls. Each LABEL element is associated with exactly one form control.

    The for attribute associates a label with another control explicitly: the value of the for attribute must be the same as the value of the id attribute of the associated control element. More than one LABEL may be associated with the same control by creating multiple references via the for attribute.