Skip to content
easeweb
Search topics

Toggle buttons that don't say whether they are pressed

A Favorite button fills its heart when pressed, but the pressed state is only a CSS class, so assistive technology hears the same button either way.

WCAG 2.2
SC 4.1.2A
Required by
Section 508 · EN 301 549 (EU)
Broken <button class="fav is-saved" aria-label="Favorite">
The accessibility problem illustrated: Saved or not? It doesn't say.
01

The problem

Screen reader users can press the Favorite button but can't tell whether the item is saved, or whether pressing it did anything.

02

Try it

Press Tab to reach the heart, then Enter or Space to press it.

The panel shows what a screen reader announces. Can you tell whether the backpack is saved?

Broken Can you fix this?

Canvas backpack

Screen reader says:

(Tab to the heart)

A recreated demo. The broken version is intentionally inaccessible.

03

The fix

Expose the pressed state with aria-pressed, a checkbox, or a name that says what pressing will do.

  1. 1Expose the state in code: aria-pressed, a checkbox, or a name that says the next action.
  2. 2Let the state or the name carry it, never both: no aria-pressed on a name that changes.
  3. 3Draw the pressed look from the value that is announced, and not by colour alone.
Before A button that only draws its state
<button type="button" class="fav" aria-label="Favorite">  <svg aria-hidden="true" viewBox="0 0 24 24"><path d="…"/></svg></button>
After

A toggle button with aria-pressed

<button type="button" class="fav" aria-pressed="false" aria-label="Favorite">  <svg aria-hidden="true" viewBox="0 0 24 24"><path d="…"/></svg></button>

Fixing this with an AI coding assistant? Get this guide as Markdown

04

Verify the fix

5 checks.

Test with: Keyboard, Screen reader, Forced colors, Mouse

0 of 5 checked

Record the OS, browser and assistive-technology versions, the build, the date, and the actual result of each step. Repeat after the shared button component changes.

Limits

This is a starting pattern, not a guarantee for every application. Screen readers word toggle buttons differently, and whether a changed name is announced depends on the screen reader and browser. The CSS is a sketch; check the focus indicator and the contrast of the heart against your own palette. Test the complete journey, from saving an item to finding it in the favorites list, with your target assistive technology.

This is a recreated teaching example, not a finding about a named client. The code is a starting pattern: test it in your own product. No completed assistive-technology test is claimed here.

Keep this fixed as your code changes.

Turn guides like this into rules your coding agents and CI follow, then have the result retested with a keyboard and screen readers.

How retests work