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: No vision:Is it saved or not?
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?

BrokenA button that only draws its state
Canvas backpack

A recreated demo. The broken version is intentionally inaccessible.

03

The fix

Make the button say whether it is pressed

Before
BrokenA 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>
What is wrong3 points

The button can be reached with Tab and pressed with Enter and Space. Its state is where it fails.

  • Assistive technology can't tell whether the backpack is saved. The state is only the is-saved class, and nothing in the accessibility tree says pressed.
  • A screen reader announces "Favorite, button" whether the backpack is saved or not.
  • It says nothing when the state changes.
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>
How it is fixed3 steps
  1. Add aria-pressed="false". It makes the button a toggle button, announced as "Favorite, toggle button, not pressed". The name stays "Favorite" and the state does the rest.
  2. On click, flip aria-pressed, so the button is announced as "pressed" when it changes.
  3. Fill the heart from the attribute, not from a class, so the picture and the announcement come from one value and can't drift apart.

This fixes the Before and passes 4.1.2.

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.

How screen readers handle aria-pressed

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. aria-checked on a button, or aria-pressed with a value ARIA doesn't define, is covered in invalid ARIA that misleads screen readers. Test the complete journey, from saving an item to finding it in the favourites 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.

EaseWeb service

Fixed it? Keep it from coming back.

I turn guides like this one into rules your coding agents follow and checks your CI runs. Then I retest by hand with a keyboard and screen readers, periodically.

See the service