Skip to main content
U.S. Flag

An official website of the United States government

Accordion

An accordion is a list of headers that hide or reveal additional content when selected.

Examples

Loading

Code

React

An accordion is made up of one <Accordion> component wrapping one or more <AccordionItem> components. See the sections below for information on each.

<Accordion> component

React Properties Documentation
NameTypeDefaultDescription
borderedbooleanApplies a border to the accordion content.
classNamestringClass to be applied to the outer <div> that contains all accordion items.

<AccordionItem> component

React Properties Documentation
NameTypeDefaultDescription
buttonClassNamestringClass to be applied to the header <button> of an accordion item.
contentClassNamestringClass to be applied to the content <div> tag of an accordion item.
defaultOpenbooleanBoolean to expand the accordion.
headingrequiredReactNodeText for the accordion item heading.
headingLevel"1" | "2" | "3" | "4" | "5" | "6"2Heading type to override default <h2>.
idstringIf not provided, a unique id will be automatically generated and used.
isControlledOpenbooleanSets the accordion panel's open state. Use this in combination with onChange for a controlled accordion; otherwise, set defaultOpen.
onChange() => voidA callback function that's invoked when a controlled accordion panel is selected or deselected.
closeIconReactNode( <RemoveIcon className="ds-c-accordion__button-icon" title={t('accordion.close')} ariaHidden={false} /> )Icon to overwrite default close icon
openIconReactNode( <AddIcon className="ds-c-accordion__button-icon" title={t('accordion.open')} ariaHidden={false} /> )Icon to overwrite default open icon

Styles

The following CSS variables can be overridden to customize Accordion components:

CSS variables for accordion
VariableDefault Core Theme Value
--accordion__colorhex value: #262626--color-base
--accordion__background-colorhex value: #f2f2f2--color-gray-lightest
--accordion__background-color--hoverhex value: #d9d9d9--color-border
--accordion__border-colorhex value: #f2f2f2--color-gray-lightest
--accordion-button__colorhex value: #262626--color-base
--accordion-content__background-colorhex value: #ffffff--color-white

Guidance

When to use

  • Use an accordion to see an overview of multiple, related sections of content
  • Use an accordion to show and hide sections as needed

When to consider alternatives

Accordions hide content from users and not everyone will notice them or understand how they work. Accordions increase cognitive load and interaction cost, as users have to make decisions about what headers to click on.

  • Don't use an accordion if users need to see most or all of the information on a page.
  • Don't use an accordion if there is not enough content to warrant condensing.

Usage

  • Make the entire header selectable. Allow users to click anywhere in the header area to expand or collapse the content; a larger target is easier to manipulate.
  • Give interactive elements enough space. Make sure interactive elements within the collapsible region are far enough from the headers that users don’t accidentally trigger a collapse.

Accessibility

Keyboard support for the Accordion header includes:

  • Enter or Spacebar - Changes the collapsed/expanded state of the associated accordion panel
  • Arrow Down - Moves focus to the next accordion header
  • Arrow Up - Moves focus to the previous accordion header

Component maturity

For more information about how we tested and validated our work for each checklist item, read our component maturity documentation.

Accessibility

  • Color

    Meets AA color contrast standards for accessibility and color blindness.
    Complete
  • Forced Colors Mode (FCM)

    While using FCM the components text is legible and improves readability.
    Complete
  • WCAG 2.1 Level AA Conformance

    All Axe checks for WCAG AA compliance have passed.
    Complete
  • Screen readers

    VoiceOver, NVDA, and JAWS screen readers provide concise communication and interaction.
    Complete
  • Keyboard navigation

    Component is fully navigable with a keyboard.
    Complete

Code

  • Storybook

    Component has stories to cover all defined props.
    Complete
  • Responsive

    Component designed to work in all responsive breakpoints.
    Complete
  • Spanish translations

    Includes Spanish translations for default text content.
    Complete

Tokens

  • Code

    Tokens implemented in code.
    Complete
  • Design

    Tokens implemented in the Sketch.
    Complete