If I have an input with its aria-label
set to 1
and an associated label set to 2
, what will be calculated as aria label of an element, referencing the input?
<input type="radio" id="cpp-search-video-btn" aria-label="1" role="tab">
<label for="cpp-search-video-btn" aria-hidden="true">2</label>
<div id="cpp-search-video-tab" aria-labelledby="cpp-search-video-btn" role="tabpanel">…</div>
What’s the aria label of the div#cpp-search-video-tab
: 1, 2, or, maybe, unset? (I want it to be "1").
As far as I see, there is no information on substitutions at MDN.
2
Answers
Well, if I get it right and “Accessibility” pane in DevTools shows the aria label in the “Computed Properties” → “Name” section, the answer is “1”.
The answer is indeed 1. ATtribute aria-labelledby has priority over aria-label, which itself has priority over
<label>
. See MDNHowever, if I can add another comment on your code:
It would be better to avoid using aria-hidden and ARIA at all if possible. The following code would be qualitatively better as pair the first rule of ARIA: don’t use it, unless you really need.
Or maybe at least:
More generally, if you have a real
<label>
, there shouldn’t be any need to override it with aria-label. Otherwise it doesn’t make much sense to have the<label>
at the first place.