On this page
Accordion
Accordions let users show and hide sections of related content on a page.
- Overview
- Rules and guidance
- Properties
- Styles
- Accessibility
When to use
- To show an overview of multiple related sections of content, where users can selectively reveal what is relevant to them
- To let users compare details across sections without having to navigate away
- For frequently-asked-question lists where most users will not read every answer
- When page length would otherwise be very long and most content is optional for any given user
When not to use
- When the content is essential and all users must see it - place the content directly on the page as body text instead. Hiding critical information risks users missing it.
- For a sequence of questions - use a separate page per question in a multi-step form, following the one-thing-per-page pattern.
- For content that belongs in a navigation structure - use Tabs instead.
- For a single show/hide toggle - use Disclosure instead, which is lighter and does not carry the visual weight of a full accordion group.
- When you need to nest accordions - do not nest accordions inside other accordions. Flatten the content hierarchy instead.
Anatomy
- Container (the Card wrapper that groups all accordion items)
- Header (the clickable area containing the button and title)
- Toggle button (the button that expands or collapses the panel; contains the icon and title text)
- Icon (plus when collapsed, minus when expanded)
- Title (the label for the section)
- Content panel (the region revealed when the accordion is expanded; hidden from all users when collapsed)
Keyboard support
Keyboard functions
- Enter / Space: toggle the focused accordion open or closed
- Tab: move focus to the next focusable element inside the content panel (when expanded) or to the next accordion header
Basic usage
Edit live code
<AccordionGroup> <Accordion title="Where does my carbon footprint come from?"> <P>Good question. As you might have guessed from the examples above, your carbon footprint comes from many areas. Like driving your car. How you power your home. Which foods you decide to eat.</P> </Accordion> <Accordion title="How do I calculate my carbon footprint?"> <P>To calculate it, you have to add up the carbon emitted by absolutely everything you do, over time. We take you through the things you'd need to look at below.</P> <P>The average carbon footprint of a person in the UK weighs in at 6.6 tonnes. Sounds like quite a lot, doesn't it. Yikes.</P> </Accordion> </AccordionGroup>
Variants and features
Default expanded
Accordions are collapsed by default. Pass expanded to open a panel on initial render. This is useful when you want to draw attention to a specific section on page load.
Edit live code
<AccordionGroup> <Accordion expanded title="Where does my carbon footprint come from?"> <P>Good question. As you might have guessed from the examples above, your carbon footprint comes from many areas. Like driving your car. How you power your home. Which foods you decide to eat.</P> </Accordion> <Accordion title="How do I calculate my carbon footprint?"> <P>To calculate it, you have to add up the carbon emitted by absolutely everything you do, over time. We take you through the things you'd need to look at below.</P> <P>The average carbon footprint of a person in the UK weighs in at 6.6 tonnes. Sounds like quite a lot, doesn't it. Yikes.</P> </Accordion> </AccordionGroup>
Custom heading level
The accordion title renders as an h3 by default. You must use headingComponent to match the heading level to the document outline of the page it sits on.
Edit live code
<AccordionGroup> <Accordion headingComponent={Heading4} title="Where does my carbon footprint come from?"> <P>Good question. As you might have guessed from the examples above, your carbon footprint comes from many areas. Like driving your car. How you power your home. Which foods you decide to eat.</P> </Accordion> <Accordion headingComponent={Heading4} title="How do I calculate my carbon footprint?"> <P>To calculate it, you have to add up the carbon emitted by absolutely everything you do, over time. We take you through the things you'd need to look at below.</P> <P>The average carbon footprint of a person in the UK weighs in at 6.6 tonnes. Sounds like quite a lot, doesn't it. Yikes.</P> </Accordion> </AccordionGroup>
Controlled toggle
Use onToggle to respond to open/close events, for example to track analytics or to synchronise state elsewhere in the page.
onToggle does not control the panel: the accordion still manages its own open state.
Edit live code
() => { // ignore - for live code example only. const Example = () => { const [lastToggled, setLastToggled] = useState('nothing yet'); return ( <Stack spaceBetween={3}> <AccordionGroup> <Accordion title="Where does my carbon footprint come from?" onToggle={() => setLastToggled('Where does my carbon footprint come from?')} > <P>Good question. As you might have guessed from the examples above, your carbon footprint comes from many areas. Like driving your car. How you power your home. Which foods you decide to eat.</P> </Accordion> <Accordion title="How do I calculate my carbon footprint?" onToggle={() => setLastToggled('How do I calculate my carbon footprint?')} > <P>To calculate it, you have to add up the carbon emitted by absolutely everything you do, over time. We take you through the things you'd need to look at below.</P> </Accordion> </AccordionGroup> <P>Last toggled: {lastToggled}</P> </Stack> ); } return <Example />; }
Grouping
Wrap related accordion items in AccordionGroup. The group provides the Card container and the dividers between items.
Do not place a single accordion item outside an AccordionGroup unless you have a strong reason. A lone accordion without its group container loses the visual structure that helps users understand the pattern.
usage
- Accordion must not be used to hide content that all users must see to complete their taskHidden content is easy to overlook. If the content is critical, place it directly on the page.Copy rule ID for accordion.non-essential-content
- Accordion must not be used as a container for a sequence of questions in a multi-step flowMulti-step question sequences belong on separate pages, following the one-thing-per-page pattern.Copy rule ID for accordion.no-question-sequences
- Accordion headingComponent must match the heading level required by the document outline of the page it sits onIncorrect heading levels break the page's document structure and confuse screen reader users navigating by headings.Copy rule ID for accordion.heading-level
content
- Accordion title must be unique within its AccordionGroupDuplicate titles make it impossible for users navigating by heading or button list to distinguish between items.Copy rule ID for accordion.title.unique
- Accordion title should be short and scannable so users can decide whether to expand without reading the panel contentAccordion titles act as navigation labels. Long or vague titles undermine the component's purpose.Copy rule ID for accordion.title.concise
- Accordion title should not end with a full stop or colonCopy rule ID for accordion.title.no-terminal-punctuation
interaction
- Accordion toggle button will be rendered as a native HTML button element. The component outputs a styled <button type="button"> automaticallyCopy rule ID for accordion.button-is-button
- Accordion toggle button will have aria-expanded set to the current open state of its panel. The component sets this automatically on every renderCopy rule ID for accordion.aria-expanded
- Accordion toggle button will reference the id of its content panel via aria-controls. The component generates a unique id per instance and wires this automaticallyCopy rule ID for accordion.aria-controls
- Accordion content panel will have role="region" and be labelled by its toggle button via aria-labelledby. The component sets both attributes automaticallyCopy rule ID for accordion.region-labelled
- Accordion content panel will be hidden from all users, including screen reader users, when the accordion is collapsed. The component sets the hidden attribute automaticallyCopy rule ID for accordion.hidden-when-collapsed
- Accordion toggle button will display a visible focus ring when focused via keyboard. The component applies the Nebula focusRing style via :focus-visible automaticallyCopy rule ID for accordion.focus-ring
composition
- Accordion must not be nested inside another AccordionNested accordions create a confusing information hierarchy and compound the risk of users missing content.Copy rule ID for accordion.no-nesting
- Accordion should be wrapped in an AccordionGroupAccordionGroup provides the Card container and the dividers between items. A lone accordion without it loses its visual structure.Exception: there is a deliberate design reason to render a standalone accordion without the group containerCopy rule ID for accordion.group-wrapper
- Accordion content panel should not contain the only instance of a primary action on the pageAn action that is hidden by default risks being missed. Place primary actions outside the accordion where they are always visible.Copy rule ID for accordion.content.no-critical-actions-only
- Accordion icon should not be replaced with a different iconThe plus/minus icon is a recognised convention for expand/collapse. Using a different icon, such as a chevron, is inconsistent with this pattern in Nebula.Copy rule ID for accordion.icon.no-override
grouping
- AccordionGroup may allow multiple panels to be open at the same timeThe default allows any number of panels to be open. Whether to restrict to one open panel at a time is a product decision. Neither is universally correct.Copy rule ID for accordion.group.single-open
Accordion
Also accepts all props from HTMLAttributes.
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
children | ReactNode | — | No | Content revealed when the accordion is expanded. |
title | ReactNode | — | Yes | Content of the button that expands and collapses the accordion. |
expanded | boolean | false | No | Whether the accordion starts expanded. Only read on first render. |
onToggle | CallableFunction | — | No | Called with the new expanded state (`true` or `false`) when the user toggles the accordion. |
inline | boolean | — | No | Has no effect. |
headingComponent | string | ComponentType<any> | Heading3 | No | Element or component used to render the title's heading. |
AccordionGroup
Also accepts all props from HTMLAttributes.
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
inline | boolean | — | No | Has no effect. |
as | ElementType | — | No | Renders the component as a different element or component, e.g. `as="section"`. |
forwardedAs | ElementType |