I have a HTML structure like this:
<fieldset>
<legend>Legend</legend>
<span>Labeltext</span>
<button aria-pressed="false">Filter 1</button>
<button aria-pressed="true">Filter 2</button>
</fieldset>
The span-Element acts like a label for the two buttons. Each button acts independently. As the design is given, it is not possible to change the structure of the text.
As far as i know, it is not possible to add one label to two buttons.
Is it sufficient to extend the label of the buttons and add the "label" (span) into it? Like this: <button aria-pressed="false" aria-label="Labeltext Filter 1">Filter 1</button>
The alternative would be to use the Checkbox Pattern from the ARIA Authoring Practices Guide (APG), which would change the "label" (span) into a heading. But there is no other heading around, so this might be more confusing for screenreader user.
Technically you can use the same element as a label for several elements simply by referring to it via
aria-labelledby.This would result in the same accessible name for both buttons, which is not very helpful. So you will need add their own contents as well. Directly providing it inside
aria-labelwould be easiest:I’m curious about the actual use case, since there already is the Legend which sufficiently provides a wrapping label for both buttons. The additional Labeltext seems unnecessary.
You can use
aria-describedbyif the Labeltext “describes or annotates the current element”: