Filter 1
Login Or Sign up

Screenreader Accessibility: two buttons, one label

42 Views Asked by At

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.

1

There are 1 best solutions below

0
Andy On

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-label would be easiest:

<fieldset>
  <legend>Legend</legend>
  <span>Labeltext</span>
  <button aria-pressed="false" aria-label="Labeltext Filter 1">Filter 1</button>
  <button aria-pressed="true" aria-label="Labeltext Filter 2">Filter 2</button>
</fieldset>

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-describedby if the Labeltext “describes or annotates the current element”:

<fieldset>
  <legend>Legend</legend>
  <span id="button-desc">Labeltext</span>
  <button aria-pressed="false" aria-describedby="button-desc">Filter 1</button>
  <button aria-pressed="true" aria-describedby="button-desc">Filter 2</button>
</fieldset>