Accordion UI Design: When to Use Accordions and How to Build Them Accessibly
Accordions are one of the most common interface components on the web: FAQ lists, product specifications, filter panels, mobile menus. They are also one of the most frequently built badly, with clickable div elements that keyboards can’t reach, states that screen readers never announce and content loaded only after a click.
This guide covers when an accordion is the right choice, how to design one that users understand, and two accessible ways to build it, with code our front-end team uses on client projects.
What an accordion is
An accordion is a vertically stacked set of headers, each of which reveals or hides a panel of content. Each item has three parts:
- The header or trigger: a clearly labeled control the user clicks or taps.
- The state indicator: usually a caret or chevron that points down when closed and up when open, or a plus and minus sign.
- The panel: the content that is shown or hidden.
Accordions are a form of progressive disclosure. They show an overview first and let users choose which detail to open, which reduces cognitive load on content-heavy pages.
When accordions help, and when they hurt
Accordions work well when:
- Users need only one or two sections from a longer set, as in FAQs, product specifications or policy details.
- The page is long on mobile and collapsing sections makes the overall structure visible.
- Section headings are clear enough that users can predict what each panel contains.
Accordions hurt when:
- Most visitors need most of the content. Making them open every panel adds clicks and hides information they came for.
- There are only two or three short sections. Showing the content is simpler.
- Users need to compare information across sections, which is hard when only one is open at a time.
- Accordions are nested inside accordions. Hierarchies of collapsed content quickly become hard to navigate.
- Critical information, such as pricing terms or required steps, is hidden behind a click.
Design guidelines
- Write specific headings. “Shipping times and costs” is more useful than “Shipping”.
- Make the whole header clickable, not only the icon, with a generous tap target on mobile.
- Show the state clearly. A caret or chevron that rotates when the panel opens is widely understood. Place it consistently, usually on the right.
- Separate items visibly with dividers or spacing so users can see where one item ends and the next begins.
- Decide whether multiple panels can be open. Allowing several open at once is usually better for users; closing others automatically only makes sense when space is tight.
- Consider an “Expand all” control for long reference content, so users can print or search the whole page.
Option 1: native details and summary
The simplest accessible accordion uses HTML’s built-in details and summary elements. The browser handles keyboard support, the open and closed state and screen reader announcements, with no JavaScript:
<details name="faq">
<summary>How long does a typical project take?</summary>
<p>Timelines depend on scope and are confirmed in the proposal.</p>
</details>
<details name="faq">
<summary>Do you work with agencies?</summary>
<p>Yes. We work as a white-label development partner for agencies.</p>
</details>
Giving several details elements the same name attribute makes them exclusive, so opening one closes the others. Current versions of Chrome, Edge, Firefox and Safari support it; omit name if users should be able to open several at once.
Style the default marker away and add your own chevron:
summary {
list-style: none;
cursor: pointer;
display: flex;
justify-content: space-between;
align-items: center;
padding: 1rem 0;
font-weight: 600;
}
summary::-webkit-details-marker { display: none; }
summary::after {
content: "";
width: 0.6em;
height: 0.6em;
border-right: 2px solid currentColor;
border-bottom: 2px solid currentColor;
transform: rotate(45deg);
transition: transform 0.2s ease;
}
details[open] > summary::after { transform: rotate(-135deg); }
summary:focus-visible {
outline: 3px solid #1d4ed8;
outline-offset: 2px;
}
Use details and summary for FAQs and simple disclosure. Choose the ARIA pattern below when you need full control over heading levels, animation or behavior.
Option 2: the ARIA button pattern
The WAI-ARIA Authoring Practices accordion pattern uses a real button inside a heading. The button’s aria-expanded attribute tells assistive technology whether the panel is open, and aria-controls points to the panel it controls.
<div class="accordion">
<h3 class="accordion__heading">
<button type="button" class="accordion__trigger" id="acc-btn-1"
aria-expanded="false" aria-controls="acc-panel-1">
<span>Shipping times and costs</span>
<svg class="accordion__icon" aria-hidden="true" focusable="false"
viewBox="0 0 24 24" width="20" height="20">
<path d="M6 9l6 6 6-6" fill="none" stroke="currentColor" stroke-width="2"/>
</svg>
</button>
</h3>
<div class="accordion__panel" id="acc-panel-1"
role="region" aria-labelledby="acc-btn-1" hidden>
<p>Orders ship within two business days. Delivery times and costs are
calculated at checkout.</p>
</div>
</div>
document.querySelectorAll('.accordion__trigger').forEach((button) => {
const panel = document.getElementById(button.getAttribute('aria-controls'));
button.addEventListener('click', () => {
const isOpen = button.getAttribute('aria-expanded') === 'true';
button.setAttribute('aria-expanded', String(!isOpen));
panel.hidden = isOpen;
});
});
A few details make this pattern work properly:
- Use a real button. It is focusable and responds to Enter and Space automatically. A clickable
divneeds extra code to do the same and is easy to get wrong. - Wrap the button in a heading at the right level for the page, so screen reader users can navigate between sections by heading.
- Use the
hiddenattribute (ordisplay: none) for closed panels, so their content is skipped by keyboard and screen readers until opened. - Use
role="region"sparingly. It helps when there are a few panels, but on long lists of many panels it creates noise for screen reader users, so it can be left off. - Progressively enhance. If the panels are rendered open and JavaScript adds the
hiddenattribute on load, the content is still available if scripts fail.
Keyboard support
At a minimum, every accordion header must be reachable with Tab and toggled with Enter or Space, with a visible focus indicator. Both options above give you that. The ARIA pattern also describes optional keys that help on long accordions:
- Down Arrow and Up Arrow move focus to the next or previous header.
- Home and End move focus to the first or last header.
Focus should stay on the header when a panel opens. Don’t move focus into the panel automatically.
Animation and reduced motion
A short transition helps users see what changed, but it should be quick and it should respect the user’s operating system preference for reduced motion. For the ARIA pattern, rotate the icon and keep the panel change instant or near-instant:
.accordion__icon {
transition: transform 0.2s ease;
}
.accordion__trigger[aria-expanded="true"] .accordion__icon {
transform: rotate(180deg);
}
@media (prefers-reduced-motion: reduce) {
.accordion__icon,
summary::after {
transition: none;
}
}
Avoid animating panel height with JavaScript on every frame. It causes layout work on each step and can hurt Interaction to Next Paint on slower phones.
Accordions and SEO
Search engines index content inside accordions as long as it is in the page’s HTML when it loads. Google has said that content hidden for user experience reasons on mobile, such as in tabs and accordions, is treated normally under mobile-first indexing. The risk comes from panels that load their content with JavaScript only after a click: crawlers don’t click, so that content may never be seen.
For FAQ sections, FAQPage structured data is still valid schema.org markup and helps machines understand the questions and answers. Since 2023, Google shows FAQ rich results only for a limited set of authoritative government and health websites, so don’t expect the expanded result in search for most sites. Only mark up questions and answers that are visible on the page.
Accordions on mobile
Accordions are most useful on small screens, where a long page of specifications or policies can be reduced to a scannable list of headings. A few mobile-specific points:
- Keep headers at least 44 pixels tall so they are easy to tap.
- When a long panel opens, make sure the header stays in view so users know where they are.
- Don’t collapse content on mobile that is visible on desktop if mobile users need it just as much.
Our mobile UX guide covers mobile navigation patterns, including accordion menus, in more detail.
Frequently asked questions
Should I use details and summary or a custom accordion?
Use details and summary when you want a simple, robust disclosure with no JavaScript. Use the ARIA button pattern when you need specific heading semantics, custom animation or behavior such as “expand all”.
Which icon should an accordion use?
A caret or chevron that rotates between closed and open is the most widely understood. Plus and minus signs also work. Whatever you choose, use it consistently and make the whole header clickable, not only the icon.
Does hiding content in an accordion hurt SEO?
Not if the content is in the HTML when the page loads. Problems arise when panel content is fetched only after a click, because search engine crawlers don’t interact with the page.
Can accordions be nested?
They can, but it’s rarely a good idea. Nested accordions make content hard to find and navigate. Consider separate pages, tabs or a clearer heading structure instead.
Build accessible components with Hey Reliable
Hey Reliable builds accessible, well-tested interface components for WordPress, Webflow and custom front ends, and reviews existing sites against WCAG. Learn more about our front-end development, UI/UX services and accessibility audits, or get a proposal for your project.
Get started now
Start with a risk-free, no obligation proposal delivered to your inbox in one business day or less.
Get Started- 5-Star Rated Technical Partner
- 100% White-Label - Sign our NDA
- 90-Day Code Guarantee