The for attribute connects a <label> to a form control by matching that control’s id. Users can click the label text to focus the field or toggle a checkbox, and screen readers announce the connection clearly.
01
Label Element
Primary use case.
02
Matches id
for equals id value.
03
Click Target
Bigger tap area.
04
Checkboxes
Toggle on label click.
05
htmlFor
JS property name.
06
Implicit Label
Wrap input option.
Fundamentals
Purpose of for
The primary purpose of the for attribute is to establish an explicit relationship between a label and a form control. When the values match, the browser treats the label as belonging to that control.
This improves accessibility because assistive technologies read the label when the control receives focus. It also improves usability: clicking label text focuses text inputs or toggles checkboxes and radio buttons, giving users a larger click target.
💡
for must match a unique id
The value of for must exactly equal the id of one labelable element on the page. Duplicate ids break the association.
Foundation
📝 Syntax
Add for to a <label> and set the linked control’s id to the same value:
Every visible field has a programmatic label. Screen readers announce “Email” when the email field is focused, and users can click either label to jump to its field.
Dynamic Values with JavaScript
Update the association at runtime with the htmlFor property:
In JavaScript, use label.htmlFor instead of label.for because for is a reserved keyword.
How It Works
Setting htmlFor re-points the label to a different control. Useful when UI layout changes dynamically or when reusing one label element in a wizard step.
A11y
♿ Accessibility
Every input needs a label — Use for + id or wrap the control inside <label>.
Do not rely on placeholder alone — Placeholders disappear when typing and are not a substitute for labels.
Checkboxes and radios benefit most — Small controls are hard to tap; labels enlarge the target.
Keep ids unique — Duplicate ids break label association and confuse assistive tech.
🧠 How for Works
1
Author sets for and id
Label for value matches control id.
Markup
2
Browser links label to control
Accessibility tree records the relationship.
A11y
3
User clicks label text
Control receives focus or toggles state.
Interaction
=
♿
Inclusive, easier forms
Clear names for fields and larger click targets for everyone.
Compatibility
Browser Support
The for attribute on <label> is supported in all modern browsers. It has been a core HTML feature for decades.
✓ HTML4+ · Fully supported
Universal label association
All major browsers honor for on label elements.
100%Browser support
Google ChromeFully supported
Full support
Mozilla FirefoxFully supported
Full support
Apple SafariFully supported
Full support
Microsoft EdgeFully supported
Full support
for attribute100% supported
Bottom line: Always associate labels with controls using for or implicit wrapping.
Pro Tips
💡 Best Practices
✅ Do
Match for exactly to a unique id on the control
Label every input, select, and textarea
Use for when label and input are in separate layout cells
Use htmlFor in JavaScript, not for
Test by clicking label text to confirm focus
❌ Don’t
Reuse the same id on multiple elements
Leave inputs without an accessible name
Point for at a non-existent id
Rely on placeholder text instead of labels
Put for on input elements instead of labels
Wrap Up
Conclusion
The for attribute is essential for accessible HTML forms. It links label text to form controls, improves keyboard and screen reader support, and gives users a larger area to click or tap.
Pair every for with a matching id, or wrap controls inside labels when layout allows. Use htmlFor in JavaScript when you need to change the association dynamically.