Skip to main content

Accordion

Stacked sections that expand and collapse without leaving the page.

In Dense data

See it live​

Start Storybook to see it live: npm run storybook

When to use it​

In Dense data: Optional detail on one record that analysts may skip. Not for fields they use every day, and not in the queue.

  • Use it when: Optional detail, questions and answers, grouped content people may skip.
  • Not when: A decision that blocks the page, a side panel, or a hint on hover.

Instead:

  • Tabs: Peer views of the same thing, one at a time.
  • Collapsible: A single section, not a stack.
  • Dialog: A blocking decision.

Words​

  • Lead with the object, then the state: "Alert 2041 contained."
  • Use numbers, not words for numbers.
  • One verb per button. No "please", no exclamation marks.
  • Use: Investigate, Filter, Assign, Escalated, Resolved. Avoid: Oops, Awesome, Please, Simply.

The labels components use, from the voice tokens:

  • content.action.commit: Save
  • content.action.cancel: Cancel
  • content.action.destroy: Delete
  • content.action.retry: Retry
  • content.action.empty-action: Change filters

See Voice and tone for the whole voice.

Accessibility and keyboard​

KeyboardWhat happensNot
undefinedEnter or Space opens and closes the focused section.undefined

Test before you ship:

  • Each header is a button inside a heading and says whether it is open. undefined

Use it in code​

npx open-ds add accordion

The component reads only component keys and semantic tokens, so it follows the brand and mode on <html>.

Tokens it reads​

Accordion reads 16 tokens of its own, each an alias of a semantic token. Each row is one part: its own token, the semantic it aliases, and the value it ends at. Change a semantic and every component that reads it follows; override one of Accordion's tokens to change Accordion alone.

Changes with theme

Dense data decides what changes when you switch theme. Here a switch changes colors only, so the marked rows differ between light and dark; everything else holds steady.

PartIts token and the semantic it aliasesValue
Accordion
Divider
Changes with theme
component.accordion.dividercolor.border.defaultvar(--accordion-divider)Lightslate.light.200:#DDE2EADarkslate.dark.100:#262D38
Trigger
Text
Changes with theme
component.accordion.trigger.labelcolor.text.primaryvar(--accordion-trigger-label)Lightslate.light.900:#161B23Darkslate.dark.900:#F7F8FA
Text sizecomponent.accordion.trigger.font-sizetype.body.font-sizevar(--accordion-trigger-font-size)font.size.14:0.875rem
Weightcomponent.accordion.trigger.font-weighttype.label.font-weightvar(--accordion-trigger-font-weight)font.weight.500:500
Padding, top and bottomcomponent.accordion.trigger.padding-yspace.inset.containervar(--accordion-trigger-padding-y)space.16:1rem
Gapcomponent.accordion.trigger.gapspace.gap.groupvar(--accordion-trigger-gap)space.16:1rem
Cornercomponent.accordion.trigger.radiusradius.controlvar(--accordion-trigger-radius)radius.2:0.125rem
Focus ring offset focus
Changes with theme
on focus
component.accordion.trigger.focus-ring-offset-focuscolor.surface.canvasvar(--accordion-trigger-focus-ring-offset-focus)Lightslate.light.50:#F7F8FADarkslate.dark.0:#0D1117
Focus ring
Color
Changes with theme
on focus
component.accordion.focus-ringcolor.border.focusvar(--accordion-focus-ring)Lightviolet.light.600:#4B3FD9Darkviolet.dark.600:#A9A3F6
Width
on focus
component.accordion.focus-ring.widthborder-width.focusvar(--accordion-focus-ring-width)border-width.2:2px
Disabled
Opacity
when disabled
component.accordion.disabled.opacityopacity.disabledvar(--accordion-disabled-opacity)opacity.40:0.4
Icon
Color
Changes with theme
component.accordion.iconcolor.text.mutedvar(--accordion-icon)Lightslate.light.600:#535D6DDarkslate.dark.400:#969FAD
Sizecomponent.accordion.icon.sizesize.iconvar(--accordion-icon-size)size.16:1rem
Speedcomponent.accordion.icon.durationmotion.duration.feedbackvar(--accordion-icon-duration)duration.fast:120ms
Content
Text sizecomponent.accordion.content.font-sizetype.body.font-sizevar(--accordion-content-font-size)font.size.14:0.875rem
Padding, bottomcomponent.accordion.content.padding-bottomspace.inset.containervar(--accordion-content-padding-bottom)space.16:1rem