The for attribute connects UI text to related controls. On a <label>, its value is the id of the form control that label describes. On an <output>, its value is a space-separated list of ids for elements that feed the result.
Explicit labeling improves accessibility (screen readers announce the name) and usability (clicking the label focuses or toggles the control). You can also wrap a control inside <label> for an implicit association without for.
Baseline · Widely available.
Not deprecated and not experimental. Stable label association across modern browsers. Applies to <label> and <output> only.
JavaScript: use htmlFor.
for is a reserved word in JavaScript. Read and write the attribute with labelElement.htmlFor.
Syntax
HTML Syntax
syntax.html
<label for="element_id">
On <output>, list one or more ids: for="id1id2".
Values
Attribute Values
Meaning depends on the element that carries for:
Element
Value
Try it
<label>
One id of a labelable control (input, select, textarea, and more)
Move the slider or change the number — the sum updates.
How It Works
Name the sources.for="a b" lists the ids that feed the calculation.
Space-separated. Unlike label, output may reference several elements.
Script updates the value.for documents the relationship; JavaScript still computes the number.
Accessibility hint. Assistive tech can treat the result as related to those inputs.
Edge Cases & Pitfalls
Most bugs are mismatched ids or putting for on the wrong element.
match
Ids must match exactly
Typos, wrong case, or a missing control mean the label does nothing useful. Keep ids unique in the whole document.
scope
Only on label and output
Do not put for on <input>. Controls use id; labels and outputs use for.
labelable
Target must be labelable
If for points at a non-labelable element (or input type="hidden"), the association has no effect.
a11y
Avoid interactive content inside labels
Links or nested buttons inside a <label> make activation confusing. Keep terms links outside the label when possible.
script
Use htmlFor in JavaScript
element.for is not the HTML attribute API. Set label.htmlFor = "id" instead.
Compatibility
Browser Support
for is an HTML attribute for label and output in the browser. It is not a Node.js, Deno, or Bun API.
✓ Baseline · Widely available
for
Label association with for is universal in modern and legacy browsers. The output for attribute is widely supported in current Chrome, Firefox, Safari, and Edge.
100%Global support (approx.)
Google ChromeAll modern
Full support
Mozilla FirefoxAll modern
Full support
Apple SafariAll modern
Full support
Microsoft EdgeAll modern
Full support
OperaAll modern
Full support
Samsung InternetModern
Full support
Internet Explorerlabel for: yes
Supported
forWidely supported
Bottom line: Safe to rely on for label–control association everywhere. Prefer explicit for + id when layout keeps the label and control apart.
Remember
Key Takeaways
Role: on label, point to one control id; on output, list related ids.
Elements: only <label> and <output>.
Alternative: wrap the control in <label> for an implicit link (no for required).
Script: use htmlFor, not for.
One line:for links a label (or output) to control ids — match carefully and keep ids unique.
Frequently Asked Questions
On a label, for holds the id of the form control that label describes. Clicking the label focuses or activates that control. On an output element, for is a space-separated list of ids of elements that contribute to the result.
label and output. Labels are the common case for form fields. Controls themselves use id; they do not take for.
A single id that matches one labelable control in the same document — for example an input (not type=hidden), select, textarea, button, meter, progress, or output.
No. Wrapping the control inside the label creates an implicit association without for. Explicit for + id is still preferred when the label and control are separate in the layout, and for assistive-tech compatibility.
Use labelElement.htmlFor because for is a reserved word in JavaScript. Reading or writing htmlFor updates the for attribute.
It is Baseline widely available. Label association with for has worked in major browsers for decades. The output for attribute is also widely supported in modern browsers.