Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can an input field have two labels?

Mary had a little form, and its fields where labeled just so.
Whenever an error crept in, confusion it would sow.

I've got a label for each input field... pretty standard affair. After validating the form, I'm displaying a helpful little paragraph at the top of the form detailing what information is missing or incorrect.

Can I have two labels for the same input field? One in the form proper, and one in the validation reminder text? Is there any reason I shouldn't do this?

like image 404
aslum Avatar asked Oct 18 '22 00:10

aslum


People also ask

Can input have 2 labels?

The LABEL element may be used to attach information to controls. Each LABEL element is associated with exactly one form control. Thus, each form control can be referenced by multiple labels, but each label can only reference one control.

Should input fields have labels?

Input fields without accompanying labels can lead to accessibility issues for those who rely on screen readers. If a screen reader comes across an input field without a label it will try to find some accompanying text to use as the label.

Can labels have input?

There are two ways to pair a label and an input. One is by wrapping the input in a label (implicit), and the other is by adding a for attribute to the label and an id to the input (explicit).


1 Answers

I assume this question is about HTML forms. From the specification:

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

Thus, each form control can be referenced by multiple labels, but each label can only reference one control. So if it makes sense to have a second label for a control (and in the situation you describe, it does) feel free to add a second label.

like image 188
James Sumners Avatar answered Oct 19 '22 14:10

James Sumners