An accordion is a vertical stack of interactive headings used to toggle the display of further information; each item can be 'collapsed' with just a short label visible or 'expanded' to show the full content.
Component
Accordion
Other names: Arrow toggle, Collapse, Collapsible sections, Collapsible, Details, Disclosure, Expandable, Expander, ShowyHideyThing
106 examples
Accordion
A11Y Style Guide
- jQuery
- Code examples
- Usage guidelines
- Accessibility
- Unmaintained
- Open source
Collapse
Ant Design
Ant Financial
- React
- Code examples
- Accessibility issues
- Open source
Accordion
Auro
Alaska Airlines
- Web Components
- Sass
- Code examples
- Usage guidelines
- Open source
Accordion
Backpack
Skyscanner
- Mobile
- React
- Code examples
- Usage guidelines
- Open source
- Tone of voice
Accordion
Base Web
Uber
- React
- CSS-in-JS
- Code examples
- Usage guidelines
- Open source
Accordion
BBC Global Experience Language
- Accessibility
- Usage guidelines
- Unmaintained
Accordion
Bolt Design System
Pegasystems
- Sass
- Twig
- Web Components
- Code examples
- Tone of voice
- Open source
Collapse
Bootstrap
- Sass
- Code examples
- Accessibility
- Open source
Expandable helper
Brighton & Hove City Council Website pattern library
- Unmaintained
Accordion
Carbon Design System
IBM
- React
- Vanilla JS
- Angular
- Vue
- Svelte
- Web Components
- Code examples
- Usage guidelines
- Open source
Accordion
Cauldron
Deque
- React
- CSS
- Code examples
- Usage guidelines
- Accessibility
- Open source
ExpandCollapsePanel
Cauldron
Deque
- React
- CSS
- Code examples
- Usage guidelines
- Accessibility
- Open source
Accordion
Cedar
Recreational Equipment, Inc.
- Vue
- Sass
- CSS Modules
- Usage guidelines
- Code examples
- Open source
Accordion
Chakra UI
- React
- CSS-in-JS
- Code examples
- Open source
Collapse
Chakra UI
- React
- CSS-in-JS
- Code examples
- Open source
Accordion
Clarity Design System
VMware
- CSS
- Angular
- Web Components
- Code examples
- Usage guidelines
- Open source
Stack View
Clarity Design System
VMware
- CSS
- Angular
- Web Components
- Code examples
- Usage guidelines
- Open source
Accordion
Coral
Talend
- React
- Code examples
- Tone of voice
- Open source
Accordion
Crayons
Freshworks
- Web Components
- Code examples
- Open source
Accordion
Decathlon Design System
- CSS
- React
- Svelte
- Vue
- Web Components
- Usage guidelines
- Code examples
- Accessibility
- Open source
Accordion
Dell Design System
- Vanilla JS
- Code examples
- Usage guidelines
View More/Less
Dell Design System
- Vanilla JS
- Code examples
- Usage guidelines
Accordion
eBay MIND Patterns
- Accessibility
- Usage guidelines
- Open source
Details
eBay MIND Patterns
- Accessibility
- Usage guidelines
- Open source
Expansion
eBay Playbook
- HTML
- React
- Code examples
Accordion
Elastic UI framework
Elastic
- React
- Sass
- Code examples
- Open source
Accordion
Elisa Design System
- React
- Usage guidelines
- Code examples
- Accessibility
Accordion
Flowbite
- Tailwind CSS
- Open source
- Code examples
Accordion
Forma 36
Contentful
- React
- CSS-in-JS
- Code examples
- Open source
Arrow Toggle
FutureLearn design system
FutureLearn
- React
- Usage guidelines
- Tone of voice
Collapse
Geist Design System
Vercel
- React
- Code examples
Accordion
generic-components
- Web Components
- Code examples
- Accessibility
- Open source
Disclosure
generic-components
- Web Components
- Code examples
- Accessibility
- Open source
Accordion
Gestalt
Pinterest
- React
- CSS
- Code examples
- Open source
- Usage guidelines
Accordion
giffgaff design system
- Usage guidelines
- Code examples
Accordion
GOLD Design System
Design System AU
- React
- Sass
- Code examples
- Usage guidelines
- Accessibility
- Open source
- Unmaintained
Accordion
GOV.UK Design System
- Nunjucks
- Code examples
- Usage guidelines
- Research
- Open source
Details
GOV.UK Design System
- Nunjucks
- Code examples
- Usage guidelines
- Research
- Open source
Accordion
Grommet
- React
- Code examples
- Open source
Disclosure
Headless UI
Tailwind Labs
- React
- Vue
- Code examples
- Accessibility
- Open source
Accordion
Helsinki Design System
City of Helsinki
- React
- CSS
- Code examples
- Usage guidelines
- Accessibility
- Open source
Collapsible sections
Inclusive Components
- Code examples
- Accessibility
- Unmaintained
ToggleDetails
Instructure-UI
Instructure
- React
- CSS-in-JS
- Code examples
- Accessibility
- Open source
ToggleGroup
Instructure-UI
Instructure
- React
- CSS-in-JS
- Code examples
- Accessibility
- Open source
Accordion
Jøkul Designsystem
Fremtind Forsikring
- React
- Sass
- Code examples
- Usage guidelines
- Open source
ExpandButton
Jøkul Designsystem
Fremtind Forsikring
- React
- Sass
- Code examples
- Usage guidelines
- Open source
Accordion
Lightning Design System
Salesforce
- React
- Code examples
- Usage guidelines
- Tone of voice
- Open source
Expandable Section
Lightning Design System
Salesforce
- React
- Code examples
- Usage guidelines
- Tone of voice
- Open source
Summary Detail
Lightning Design System
Salesforce
- React
- Code examples
- Usage guidelines
- Tone of voice
- Open source
Accordion
Luna
Sainsbury’s
- React
- Sass
- Usage guidelines
- Code examples
- Tone of voice
Disclosure
Mailchimp design system
- Code examples
Accordion
Momentum Design
Cisco
- React
- Sass
- Code examples
- Usage guidelines
- Open source
Details
Mozilla Protocol
- Handlebars
- Sass
- Usage guidelines
- Open source
Details component
Mozilla Protocol
- Handlebars
- Sass
- Usage guidelines
- Open source
Expandable
Nessie
Nederlandse Spoorwegen
- Web Components
- Tailwind CSS
- Usage guidelines
- Code examples
Collapse
NextUI
- React
- CSS-in-JS
- Code examples
- Open source
Expander
NHS Digital service manual
- Nunjucks
- Code examples
- Usage guidelines
- Research
- Tone of voice
- Open source
Details
NHS Digital service manual
- Nunjucks
- Code examples
- Usage guidelines
- Research
- Tone of voice
- Open source
Accordion
Nucleus Design System
British Gas
- Web Components
- Usage guidelines
Expander
Nucleus Design System
British Gas
- Web Components
- Usage guidelines
Accordion
ONS Design System
Office for National Statistics
- HTML
- Nunjucks
- Sass
- Code examples
- Usage guidelines
- Accessibility
- Open source
Details
ONS Design System
Office for National Statistics
- HTML
- Nunjucks
- Sass
- Code examples
- Usage guidelines
- Accessibility
- Open source
Accordion
Ontario Design System
Ontario Government
- HTML
- Sass
- Code examples
- Usage guidelines
- Accessibility
Accordion
Orbit
Kiwi.com
- React
- CSS-in-JS
- Usage guidelines
- Open source
- Code examples
- Tone of voice
Collapse
Orbit
Kiwi.com
- React
- CSS-in-JS
- Usage guidelines
- Open source
- Code examples
- Tone of voice
Accordion
Oxygen
Repsol
- HTML
- Code examples
- Usage guidelines
Accordion
Pajamas
GitLab
- Vue
- Usage guidelines
- Code examples
- Open source
Disclosure
Paste
Twilio
- React
- CSS-in-JS
- Usage guidelines
- Code examples
- Tone of voice
- Accessibility
- Open source
Accordion
PatternFly
Red Hat
- React
- Sass
- Tone of voice
- Open source
- Usage guidelines
Expandable section
PatternFly
Red Hat
- React
- Sass
- Tone of voice
- Open source
- Usage guidelines
Accordion
Porsche Design System
- Web Components
- Angular
- React
- Vue
- Code examples
- Open source
Details
Primer
GitHub
- React
- Code examples
- Open source
Expansion Item
Quasar Framework
- Vue
- Accessibility issues
- Code examples
- Open source
Accordion
Radix Primitives
WorkOS
- React
- Code examples
- Open source
Collapsible
Radix Primitives
WorkOS
- React
- Code examples
- Open source
Accordion
Reach UI
- React
- Accessibility
- Code examples
- Open source
Disclosure
Reach UI
- React
- Accessibility
- Code examples
- Open source
Disclosure
Reakit
- React
- Code examples
- Open source
- Accessibility
Accordion
Ruter Components
- React
- Code examples
- Unmaintained
Accordion
SEB Design Library
Skandinaviska Enskilda Banken
- Sass
- React
- Angular
- Code examples
- Usage guidelines
Section expander
SEB Design Library
Skandinaviska Enskilda Banken
- Sass
- React
- Angular
- Code examples
- Usage guidelines
Collapsible
Seeds
Sprout Social
- React
- Code examples
- Usage guidelines
- Tone of voice
Accordion Item
Seek style guide
- React
- Code examples
- Unmaintained
Toggle Content
Seek style guide
- React
- Code examples
- Unmaintained
Read More
Seek style guide
- React
- Code examples
- Unmaintained
Accordion
shadcn/ui
- React
- Tailwind CSS
- Code examples
- Open source
Collapsible
shadcn/ui
- React
- Tailwind CSS
- Code examples
- Open source
Details
Shoelace
- Web Components
- Code examples
- Open source
Accordion
Source
The Guardian
- React
- Code examples
- Usage guidelines
- Open source
Accordion
Spark Design System
Quicken Loans
- React
- Angular
- Code examples
- Usage guidelines
- Open source
- Unmaintained
Expandable
Stacks
Stack Overflow
- Stimulus
- Code examples
- Usage guidelines
- Tone of voice
- Open source
Accordion
United States Web Design System
United States government
- Nunjucks
- Code examples
- Usage guidelines
- Open source
Collapsible containers
W3C design system
- Sass
- Vanilla JS
- Code examples
- Usage guidelines
- Open source
- Accessibility
Disclosure
Wanda
Wonderflow
- React
- CSS Modules
- Code examples
- Open source
Accordion
Wanda
Wonderflow
- React
- CSS Modules
- Code examples
- Open source
Expander
Wanda
Wonderflow
- React
- CSS Modules
- Code examples
- Open source
Accordion
West Midlands Network Design System
- HTML
- Nunjucks
- Sass
- Code examples
- Usage guidelines
- Open source
Details
West Midlands Network Design System
- HTML
- Nunjucks
- Sass
- Code examples
- Usage guidelines
- Open source
Expandable container
Workday Canvas Design System
- React
- Usage guidelines
- Accessibility
- Tone of voice
- Open source
Description
The examples above use a variety of different names: many of these refer to the collapsible/expandable nature of the component, while others reference the HTML element used by their implementation: details. All of these examples have two primary elements in common: a heading and some content: interacting with the heading toggles the visibility of the content; this heading + content pattern can be repeated as many times as needed.
Markup
Approach 1: Heading with Button
Here is example markup for a single accordion item:
<h2>
<button
type="button"
aria-expanded="false"
aria-controls="accordion-item-1-content"
>
Accordion item 1
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 256 256"
aria-hidden="true"
focusable="false"
>
<polygon points="0,64 128,192 256,64" />
</svg>
</button>
</h2>
<div id="accordion-item-1-content">
<p>Accordion item 1 content</p>
</div>
This example uses an
h2
for the heading but this should be whichever heading level is appropriate for where you’re using it.Each accordion item can be in one of two states: expanded or collapsed. This is communicated to assistive technology via the
aria-expanded
attribute on the button.The
aria-controls
attribute ties the button to the content it controls using theid
of the content container (accordion-item-1-content
in the example).The button contains a downwards-pointing arrow to hint that it can be expanded. When the accordion item is in its expanded state, this is rotated 180 degrees to point upwards. It is also common to see plus (+) and minus (-) symbols used instead of arrows.
The icon in this example uses an inline SVG to render the arrow. It is given the
aria-hidden="true"
attribute to hide it from assistive technologies (as well asfocusable="false"
to address an inconsistency in Internet Explorer and older versions of Edge). You could alternatively use a CSS background image or pseudo-element.
Approach 2: Summary and Details
The following example uses the summary and details elements to achieve a similar result to the previous example, without JavaScript:
<details>
<summary>
<h2>Accordion item 1</h2>
</summary>
<p>Accordion item 1 content</p>
</details>
To set the initial state of the accordion item to be 'expanded', you can add the attribute open="true"
to the details
element (the default is false
, so this can be omitted for collapsed items).
Browser support warning: The details
and summary
elements are not supported by Internet Explorer or Opera Mini at the time of writing.1
Interactivity
The first example, requires a small amount of JavaScript to toggle the aria-expanded
attribute on the button and the visibility of the content.
In situations where JavaScript is not enabled or doesn’t work for some reason, it is desirable for the content to still be visible (because the button requires Javascript, the user has no way of making the content visible if JavaScript is disabled). Instead of making the content invisible by default or having buttons that do nothing, you can create your accordion component without the button element, and use JavaScript to progressively enhance the HTML with additional interactivity. There is an example on how to do this on Inclusive Components.
The second example works without JavaScript in browsers that support the details
element. In browsers that don’t support the details
element, all of the content will be rendered, but it won’t be collapsible.
Styling
If you go for the first approach, using a button
element which triggers some JavaScript, you can use the aria-expanded
attribute as a hook for styling the button. The following example will rotate the arrow 180 degrees when the accordion is expanded:
button[aria-expanded='true'] > svg {
transform: rotate(180deg);
}
If you decide on the details
and summary
elements instead, there are a couple of default browser styles you may want to override:2
The default cursor for the
summary
is the text selection type which doesn’t give great affordance that the element is clickable. The following CSS, will change the cursor to thepointer
style (like that shown when hovering over links):details summary { cursor: pointer; }
If you nest a block-level element like a heading in a
summary
element (as in the example above), it appears below the arrow marker. To make it appear next the the arrow, set itsdisplay
property toinline
:details summary > * { display: inline; }
Usage guidelines
Accordions work well on smaller screens, as they reduce the amount of vertical scrolling required to get an overview of the content. They also require very little horizontal space, unlike components such as tabs.
Some implementations allow for only a single accordion item to be expanded at any one time — do this with caution, as some users may wish to view the content from two items at the same time.
Be mindful that when you are using an accordion you are hiding content from users — they therefore should not be used for essential information.
- Details & Summary elements: Caniuse.com↩
- Two Issues Styling the Details Element and How to Solve Them, Greg Gibson on CSS-Tricks↩