Skip to content

fix(accessibility): associate HTML labels with their controls - #719

Merged
addyosmani merged 1 commit into
addyosmani:mainfrom
rudycelekli:fix-a11y-label-for
Oct 29, 2026
Merged

addyosmani merged 1 commit into
addyosmani:mainfrom
rudycelekli:fix-a11y-label-for

Conversation

@rudycelekli

Copy link
Copy Markdown
Contributor

Problem

references/accessibility-checklist.md shows two HTML examples under "Explicit label association" and "Accessible Lists" and uses React's htmlFor property. In HTML the content attribute is for. htmlFor is only the DOM reflection of that attribute (HTMLLabelElement.htmlFor, the for attribute).

Reproduction

Headless Chrome, the checklist's attribute versus for:

<label htmlFor="task-1" id="bad">Buy groceries</label>
<input id="task-1">
<label for="task-1" id="good">Buy groceries</label>
{"badHtmlFor":"","badControlIsInput":false,"badAttr":"task-1","goodHtmlFor":"task-1","goodControlIsInput":true}

The htmlFor label's control is null, so clicking the text does not focus the field and the accessible name is not associated. The same attribute is on the email example. Both fences are html, in the "Common HTML Patterns" section.

Change

Use for on those two labels. No other example in the file is changed.

Made with Cursor

The checklist's HTML examples used React's htmlFor property. In HTML that attribute does not set the label's for value, so the control is not labelled.

@addyosmani addyosmani left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: right, this block is HTML, so htmlFor never associated the label with its input. Merging.

@addyosmani
addyosmani merged commit 09a9144 into addyosmani:main Oct 29, 2026
7 checks passed
hillemacher pushed a commit to hillemacher/agent-skills that referenced this pull request Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants