How do I connect a form label to the right input?
Quick answer
Give the input an id, then set the label’s for value to exactly the same text. For example, for="email" connects to id="email". Check each label and input pair for an exact match. Nearby text alone does not provide the same reliable programmatic association; wrapping the input inside its label is another association method. [S1]
The question, the details, the next step.
A practical checklist
For each explicit association, compare the label’s
forvalue with the intended input’sid.Confirm the label’s wording describes the field it is connected to.
After copying or renaming a field, recheck both association values.
If using implicit association, verify that the intended input is inside its label.
Treat label pairing as one review step, not proof that the whole form is accessible.
A few more useful answers
Is text beside an input enough to connect it to the field?
No. Nearby plain text alone does not provide the same reliable programmatic association as an associated label. [S1]
Can a label contain its input instead of using `for` and `id`?
Yes. Enclosing the input inside the label is an implicit association method. [S1]
Does a matching label and input mean my entire form is accessible?
Not by itself. This check addresses label association; it does not establish that the rest of the form meets every accessibility requirement.
Sources
References used for this guide.
- [S1] HTML input element: Associating labels with inputs developer.mozilla.org · Checked
