Skip to content
easeweb
Search topics

Show and hide buttons that don't say whether they are open

A button opens and closes a panel, but open and closed live only in 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 class="filter-toggle is-open"
The accessibility problem illustrated: Open, but it only says button.
01

The problem

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

02

Try it

Press Tab to reach Filters, then Enter to open it.

The panel shows what a screen reader announces. Can you tell whether the filters are open?

Broken Can you fix this?

Screen reader says:

(Tab to Filters)

A recreated demo. The broken version is intentionally inaccessible.

03

The fix

Expose open and closed with aria-expanded on the button, or with details and summary.

  1. 1Keep the open state in step with the panel on every toggle.
  2. 2Name the button for what it shows, and keep the name fixed.
  3. 3Put the panel right after the button, and out of reach when closed.
Before A class that draws open and closed
<button type="button" class="filter-toggle">  Filters <svg class="chevron" aria-hidden="true">…</svg></button><div class="filter-panel">  <label><input type="checkbox" name="stock"> In stock only</label>  <label><input type="checkbox" name="sale"> On sale</label></div>
After

Aria-expanded on the existing button

<button type="button" class="filter-toggle" aria-expanded="false" aria-controls="filters">  Filters <svg class="chevron" aria-hidden="true">…</svg></button><div class="filter-panel" id="filters" hidden>  <label><input type="checkbox" name="stock"> In stock only</label>  <label><input type="checkbox" name="sale"> On sale</label></div>

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

04

Verify the fix

5 checks, no mouse.

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

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 toggle component changes.

Limits

This is a starting pattern, not a guarantee for every application. Screen readers word a summary differently, and some announce it as a disclosure triangle rather than a button. The script is a minimal sketch without animation or a close button inside the panel. Test the complete filtering journey 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