New New in Pro: FAQ schema and deep links, set per accordion. See what’s new

How to Build an Accessible Accordion (WCAG Checklist)

An accessible accordion works with a keyboard, a screen reader and reduced motion. Here is a practical checklist based on WCAG and the WAI-ARIA pattern.

Written by binsaifullah
  • 4 min read
  • Published
How to Build an Accessible Accordion – Easy Accordion Block guide

Accordions are everywhere, and many of them are hard to use without a mouse. An accessible accordion works for keyboard users, screen reader users and people who prefer less motion, without extra effort from them. This checklist follows WCAG 2.2 and the accordion pattern in the WAI-ARIA Authoring Practices.

1. Use a real button for each header

The header must be a focusable control. A button element is the right choice: it receives focus, responds to Enter and Space, and is announced as a button. Clickable div elements without roles or keyboard handling fail people who don’t use a mouse.

Key takeaways: Building an accessible accordion. Use a real button inside a heading; Toggle aria-expanded and label each panel; Support keyboard and keep focus visible; Respect reduced motion and check contrast.
Key takeaways: Building an accessible accordion

2. Wrap the button in a heading

Placing the button inside a heading element (for example an h3) keeps the page outline intact. Screen reader users often jump between headings to find what they need.

3. Expose the open state

Each header button needs aria-expanded="true" when its panel is open and "false" when closed. Without it, a screen reader user can’t tell what happened after pressing the button.

4. Connect the header and the panel

Give the panel an id and point to it from the button with aria-controls. Give the panel role="region" and label it with aria-labelledby pointing to the header, so it is announced with its title.

5. Support the expected keys

KeyExpected behaviour
Enter or SpaceOpens or closes the focused panel
TabMoves to the next focusable element
Down / Up arrowMoves to the next or previous header (optional but helpful)
Home / EndMoves to the first or last header (optional)

6. Make focus visible

Keyboard users must see where they are. Never remove the focus outline without replacing it with a clear focus style that meets contrast requirements.

7. Keep IDs unique

When a page has several accordions, every header and panel ID must be unique. Duplicate IDs make screen readers announce the wrong panel.

8. Respect reduced motion

Some people experience discomfort with motion. Honour the prefers-reduced-motion setting by skipping or shortening the opening animation.

9. Don’t hide content from assistive technology permanently

Closed panels should be hidden from everyone until opened, and fully available once opened. Content should also remain readable if JavaScript fails, rather than being permanently invisible.

10. Check colour contrast

Header text, icons and focus styles need enough contrast against their background, in every state: normal, hover and open.

11. Test with real tools

  1. Navigate the page with only the keyboard.
  2. Try a screen reader: VoiceOver on macOS and iOS, NVDA on Windows, TalkBack on Android.
  3. Turn on reduced motion in your system settings and reload.
  4. Run an automated checker such as Lighthouse or axe. It finds issues such as missing labels, but does not replace manual testing.

How Easy Accordion Block builds an accessible accordion

Easy Accordion Block builds these requirements in, so you don’t have to add them by hand:

  • Headers are real buttons with aria-expanded and aria-controls, and panels are labelled regions.
  • Up, Down, Home and End move between headers; Enter and Space toggle.
  • IDs stay unique, even with several accordions on one page.
  • Reduced motion is respected, panels stay readable without JavaScript, and every panel opens when the page is printed.

You can read the details in the accessibility section of the docs.

What the markup looks like

Here is a simplified example of an accessible accordion item. Easy Accordion Block generates markup along these lines for you:

<h3>
  <button type="button" aria-expanded="false" aria-controls="faq-1-panel" id="faq-1-header">
    Can I return an item?
  </button>
</h3>
<div id="faq-1-panel" role="region" aria-labelledby="faq-1-header" hidden>
  <p>Yes, within 30 days.</p>
</div>

When the button is activated, the script sets aria-expanded="true" and shows the panel.

Common accessibility mistakes

MistakeWho it affectsFix
Header is a div or spanKeyboard and screen reader usersUse a button element
No aria-expandedScreen reader usersToggle aria-expanded on open and close
Focus outline removedKeyboard usersAdd a visible focus style
Duplicate IDsScreen reader usersGenerate unique IDs per accordion
Long animations, no reduced motionPeople with vestibular disordersHonour prefers-reduced-motion
Low-contrast iconsPeople with low visionCheck contrast in every state
Content invisible without JavaScriptEveryone if scripts failKeep panels readable without JS

Frequently asked questions

Is the HTML details element accessible?

The details and summary elements are reasonably accessible out of the box, and work without JavaScript. They lack grouped behaviour and arrow-key navigation between items, which a full accordion can provide. We compare them in the next post.

Do accordions meet WCAG?

An accordion can meet WCAG 2.2 when it uses proper buttons, states, focus styles and contrast, and when it works with a keyboard.

What heading level should accordion titles use?

Use the next level below the section heading the accordion sits in, often H3. Easy Accordion Block lets you choose H2 to H6.

Written by

binsaifullah

Builds Easy Accordion Block and other Gutenberg blocks at Gutenbergkits, and writes about making WordPress sites that look great.

Leave a Reply

Keep reading

All articles