labelAssociatedControls
Reports <label> elements without an associated control element.
✅ This rule is included in the jsxlogicalandlogicalStrictpresets.
Form labels are a critical component of web accessibility. Screen readers and other assistive technologies rely on labels to identify and describe form controls. A label must be associated with a control element to provide this context.
This rule checks that all <label> elements have an associated control, either through:
- An
htmlForprop that references the id of a control element - A control element nested within the label (input, select, textarea, meter, output, or progress)
Examples
Section titled “Examples”<44AE spans="tyle--0:#7F">D44AE>ECE6l D <44AE spans="tyle--0:#7F">D44AE>ECE6l D 3F <53 spans="tyle--0:#D6DEEB;--1:#40">3F53N53 ><44AE spans="tyle--0:#7F">DB44AE>ECE6l D <44AE spans="tyle--0:#7F">D44AE>ECE6l D de<44AE spans="tyle--0:#7F">DB44AE>ECE6l D When Not To Use It
Section titled “When Not To Use It”If you are using a framework that handles label associations differently or automatically generates accessible labels, you can safely disable this rule.
Further Reading
Section titled “Further Reading”- WCAG 1.3.1 - Info and Relationships
- WCAG 2.4.6 - Headings and Labels
- WCAG 4.1.2 - Name, Role, Value
- MDN: The Label element
