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: No vision:Are the filters open?
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?

BrokenA class that draws open and closed

A recreated demo. The broken version is intentionally inaccessible.

03

The fix

Let the button say whether its panel is open

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

The button is reachable and the closed panel is properly hidden. Its state is where it fails.

  • A screen reader user can't tell whether the filters are open. Open and closed exist only as the is-open class, which the script toggles and only the CSS reads, so the button is announced as "Filters, button" in both states.
  • Pressing the button seems to do nothing. The button's state doesn't change when the panel opens, so nothing is announced.
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>
How it is fixed4 steps
  1. Give the button aria-expanded="false" and aria-controls="filters". It is now announced as "Filters, button, collapsed".
  2. Hide the closed panel with the hidden attribute instead of the class. It leaves the tab order and what a screen reader can reach.
  3. In the click handler, flip aria-expanded and set panel.hidden from it, so "expanded" is announced after the button is pressed.
  4. Draw the chevron from [aria-expanded="true"]. The picture and the announcement can't disagree, and a forgotten attribute shows as a chevron that never flips.

This fixes the Before and passes 4.1.2. hidden works only while no rule in your CSS sets display on the panel; if one does, add .filter-panel[hidden] { display: none; }.

A panel that must animate open, or one that sits away from its button, such as a button in a toolbar and a panel across the page below it, is why a toggle like this stays a button. These, and other ways to close it, can be added, as long as they leave those steps intact.

  • Animation: flip aria-expanded when the button is pressed, and make sure the panel ends with hidden set when it closes.
  • A panel placed elsewhere in the layout: move it with CSS, and keep it directly after the button in the DOM, since reading order is what connects the two.
  • Other ways to close, such as a close button in the panel or a route change: send each through the same code, so aria-expanded is updated on every path.

Easily confused
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.

How screen readers handle aria-expanded

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. A sidebar of sections that each open in this way is covered in tree views keyboards can't open and screen readers flatten. A Read more that opens a review in place is the same kind of button; when several sit on one page, name each after its item, as "Read more" links that all say the same thing shows for links. 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.

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