False Positive: Form element has multiple <label> elements
See original GitHub issueIMO this rule should be retired completely. Multiple labels for a form field are allowed by spec and work in most useragents. I believe it is only IE where they do not. This would be the simplest way to resolve.
However, even if it were to be kept the following should certainly not throw an error https://codepen.io/anon/pen/MrLgKm
<input type="checkbox" id="A" aria-labelledby="B">
<label class="indicator" aria-hidden="true" for="A">X</label>
<label for="A" id="B" class="ps-label">Yes/No Value</label>
Here there are 2 labels for the checkbox (the first is actually a CSS image in the real thing - but here I have added X for simplicity). They are both labels in order to increase the hit area for the checkbox. The first is hidden from screen readers with aria-hidden as it is not meaningful.
Even the addition of aria-labelledby on the checkbox which should override the labels does not seem to remove the aXe error.
Issue Analytics
- State:
- Created 6 years ago
- Comments:24 (18 by maintainers)
Top Results From Across the Web
Form fields do not have duplicate labels | Axe Rules
Assigning multiple labels to the same form field can cause problems for some combinations of screen readers and browsers, and the results are...
Read more >How to fix accessibility Issue for 2 forms having same fields in ...
It is currently a label element. You can change it to an aria-labelledby attribute on the input element. That allows you to chain...
Read more >Form field must not have multiple label elements
Makes certain that a form field doesn't have multiple labels. For some combinations of screen readers and browsers, adding several labels to the...
Read more ><input>: The Input (Form Input) element - HTML
The <input> HTML element is used to create interactive controls for web-based forms in order to accept data from the user; a wide...
Read more >Form element labeling is inconsistent, inflexible and bad for ...
Form labeling within D7 is inconsistent, inflexible and bad for accessibility. Inconsistent: Most form elements have their label generated ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I am re-opening this because the
aria-labelledby
is overriding the other labels. This is a case we need to support.We need to decide how to handle this case:
I have tested on VO and it works correctly but we need more evidence that this is intended and fully implemented behavior
After talking with @AutoSponge and @WilcoFiers, and running extensive tests (https://codepen.io/straker/full/PvqONy), this is what we’ve come up with:
aria-labelledby
that points to hidden labels is consistently supported.aria-labelledby
that points to multiple visible labels is not quite supported. VoiceOver on iOS fails to read all labels.Taking that all into account, I propose we update the rule to:
aria-labelledby
is present due to iOS Safari)aria-hidden
(ifaria-labelledby
is not present due to Talkback)aria-labelledby
is present (doesn’t matter if hidden viaaria-hidden
or CSS)