Skip to main contentSkip to docs navigation

Chassis

Build accordions on the native details and summary elements, with grouped items, size and context variants, and opt-in transitions.

@layer components
JavaScript is optional
Component tokens

Introduction

Accordions stack collapsible items built on the native <details> and <summary> elements. The browser expands and collapses each item, handles keyboard interaction, and exposes the expanded state to assistive technology, so the component works without JavaScript. The .accordion class on the wrapper styles the items, and the optional data-cx-accordion attribute adds height and caret transitions through the Accordion plugin.

Basic structure

Wrap <details> elements in an .accordion element. Each item holds a <summary> with an .accordion-title and an .accordion-body for the content. Items that share a name attribute form a group in which only one item is open at a time, and the open attribute renders an item expanded on load.

Accordion Item #1

This is the first item's body, shown by default. It will automatically close when another item is opened by clicking its summary element.

Accordion Item #2

This is the second item's body. It is hidden by default and will open when its summary element is clicked.

Accordion Item #3

This is the third item's body. It is hidden by default and will open when its summary element is clicked.

HTML
<div class="accordion" data-cx-accordion>
<details name="example" open>
  <summary>
    <span class="accordion-title">Accordion Item #1</span>
  </summary>
  <div class="accordion-body">
    <p>This is the <b>first item's body</b>, shown by default. It will automatically close when another item is opened by clicking its summary element.</p>
  </div>
</details>
<details name="example">
  <summary>
    <span class="accordion-title">Accordion Item #2</span>
  </summary>
  <div class="accordion-body">
    <p>This is the <b>second item's body</b>. It is hidden by default and will open when its summary element is clicked.</p>
  </div>
</details>
<details name="example">
  <summary>
    <span class="accordion-title">Accordion Item #3</span>
  </summary>
  <div class="accordion-body">
    <p>This is the <b>third item's body</b>. It is hidden by default and will open when its summary element is clicked.</p>
  </div>
</details>
</div>

Headings

The HTML spec permits one heading element as a direct child of <summary>, with no ARIA role overrides. Use a heading element as .accordion-title when accordion headers need to participate in the document's visual and source-order hierarchy.

Accordion Item #1

This is the first item's body, shown by default. It will automatically close when another item is opened by clicking its summary element.

Accordion Item #2

This is the second item's body. It is hidden by default and will open when its summary element is clicked.

Accordion Item #3

This is the third item's body. It is hidden by default and will open when its summary element is clicked.

HTML
<div class="accordion" data-cx-accordion>
<details name="example-headings" open>
  <summary>
    <h3 class="accordion-title">Accordion Item #1</h3>
  </summary>
  <div class="accordion-body">
    <p>This is the <b>first item's body</b>, shown by default. It will automatically close when another item is opened by clicking its summary element.</p>
  </div>
</details>
<details name="example-headings">
  <summary>
    <h3 class="accordion-title">Accordion Item #2</h3>
  </summary>
  <div class="accordion-body">
    <p>This is the <b>second item's body</b>. It is hidden by default and will open when its summary element is clicked.</p>
  </div>
</details>
<details name="example-headings">
  <summary>
    <h3 class="accordion-title">Accordion Item #3</h3>
  </summary>
  <div class="accordion-body">
    <p>This is the <b>third item's body</b>. It is hidden by default and will open when its summary element is clicked.</p>
  </div>
</details>
</div>

The heading level is not exposed to heading navigation in assistive technology. See Heading semantics for the consequences and the alternative.

Static items

Items without a name attribute, or with a unique one, open and close independently of the others. Grouped and independent items can be mixed in a single accordion.

Accordion Item #1

This is the first item's body, shown by default. Since it has no name attribute, it behaves independently and will only close when its own summary element is clicked.

Accordion Item #2

This item shares the example-static name attribute with Accordion Item #3, forming a group. It will automatically close when Accordion Item #3 is opened.

Accordion Item #3

This item shares the example-static name attribute with Accordion Item #2, forming a group. It will automatically close when Accordion Item #2 is opened.

HTML
<div class="accordion" data-cx-accordion>
  <details open>
    <summary>
      <span class="accordion-title">Accordion Item #1</span>
    </summary>
    <div class="accordion-body">
      <p>This is the first item's body, shown by default. Since it has <b>no name attribute</b>, it behaves independently and will only close when its own summary element is clicked.</p>
    </div>
  </details>
  <details name="example-static" open>
    <summary>
      <span class="accordion-title">Accordion Item #2</span>
    </summary>
    <div class="accordion-body">
      <p>This item shares the <b>example-static</b> name attribute with Accordion Item #3, forming a group. It will automatically close when <b>Accordion Item #3</b> is opened.</p>
    </div>
  </details>
  <details name="example-static">
    <summary>
      <span class="accordion-title">Accordion Item #3</span>
    </summary>
    <div class="accordion-body">
      <p>This item shares the <b>example-static</b> name attribute with Accordion Item #2, forming a group. It will automatically close when <b>Accordion Item #2</b> is opened.</p>
    </div>
  </details>
</div>

Layout options

Modifier classes on the .accordion wrapper change how the items sit in their container and where the caret is placed.

Flush accordion

Add .flush to remove the background colors, the outer border and the rounded corners, which renders the accordion edge-to-edge with its parent container. An accordion with a context keeps the background colors of its context.

Accordion Item #1

This is the first item's body, shown by default. It will automatically close when another item is opened by clicking its summary element.

Accordion Item #2

This is the second item's body. It is hidden by default and will open when its summary element is clicked.

Accordion Item #3

This is the third item's body. It is hidden by default and will open when its summary element is clicked.

HTML
<div class="accordion flush" data-cx-accordion>
  ...
</div>

Caret position

Add .caret-end to the .accordion wrapper to move the caret icon to the end of the summary element.

Accordion Item #1

This is the first item's body, shown by default. It will automatically close when another item is opened by clicking its summary element.

Accordion Item #2

This is the second item's body. It is hidden by default and will open when its summary element is clicked.

Accordion Item #3

This is the third item's body. It is hidden by default and will open when its summary element is clicked.

HTML
<div class="accordion caret-end" data-cx-accordion>
  ...
</div>

Animation

The data-cx-accordion attribute on the wrapper opts the accordion into transitions: the Accordion plugin animates the height of an item as it opens or closes, and the caret and the summary transition with it. Without the attribute the accordion needs no JavaScript: the content opens and closes instantly and the caret does not animate.

Chassis CSS respects user accessibility preferences by automatically disabling animations when the prefers-reduced-motion media query is detected. See the reduced motion guidelines in the accessibility documentation for implementation details.

Accordion Item #1

This is the first item's body, shown by default. It will automatically close when another item is opened by clicking its summary element.

Accordion Item #2

This is the second item's body. It is hidden by default and will open when its summary element is clicked.

Accordion Item #3

This is the third item's body. It is hidden by default and will open when its summary element is clicked.

HTML
<div class="accordion">
  ...
</div>

Sizes

In Figma

Accordions come in three sizes. The .lg and .sm classes on the .accordion wrapper change the font size, the paddings and the caret size of every item; the medium size needs no class.

Large

Add .lg for larger font size and more generous spacing. Suitable for primary content areas, FAQ sections, or hero elements where accordions need more visual prominence.

Accordion Item #1

This is the first item's body, shown by default. It will automatically close when another item is opened by clicking its summary element.

Accordion Item #2

This is the second item's body. It is hidden by default and will open when its summary element is clicked.

Accordion Item #3

This is the third item's body. It is hidden by default and will open when its summary element is clicked.

HTML
<div class="accordion lg" data-cx-accordion>
  ...
</div>

Small

Add .sm for reduced font size and compact spacing. Suitable for secondary content areas like cards, sidebars, or dense layouts where space efficiency is a priority.

Accordion Item #1

This is the first item's body, shown by default. It will automatically close when another item is opened by clicking its summary element.

Accordion Item #2

This is the second item's body. It is hidden by default and will open when its summary element is clicked.

Accordion Item #3

This is the third item's body. It is hidden by default and will open when its summary element is clicked.

HTML
<div class="accordion sm" data-cx-accordion>
  ...
</div>

Context variants

CSS Only

The .context class on the .accordion wrapper colors the borders, titles, bodies and carets from a context instead of the default palette. See context class for how contexts work.

Colors

Combine .context with a context color class, such as .primary, to set the color of the accordion.

Accordion Item #1

This is the first item's body, shown by default. It will automatically close when another item is opened by clicking its summary element.

Accordion Item #2

This is the second item's body. It is hidden by default and will open when its summary element is clicked.

Accordion Item #3

This is the third item's body. It is hidden by default and will open when its summary element is clicked.

Accordion Item #1

This is the first item's body, shown by default. It will automatically close when another item is opened by clicking its summary element.

Accordion Item #2

This is the second item's body. It is hidden by default and will open when its summary element is clicked.

Accordion Item #3

This is the third item's body. It is hidden by default and will open when its summary element is clicked.

Accordion Item #1

This is the first item's body, shown by default. It will automatically close when another item is opened by clicking its summary element.

Accordion Item #2

This is the second item's body. It is hidden by default and will open when its summary element is clicked.

Accordion Item #3

This is the third item's body. It is hidden by default and will open when its summary element is clicked.

Accordion Item #1

This is the first item's body, shown by default. It will automatically close when another item is opened by clicking its summary element.

Accordion Item #2

This is the second item's body. It is hidden by default and will open when its summary element is clicked.

Accordion Item #3

This is the third item's body. It is hidden by default and will open when its summary element is clicked.

HTML
<div class="accordion context neutral sm" data-cx-accordion>
  ...
</div>

<div class="accordion context primary sm" data-cx-accordion>
  ...
</div>

<div class="accordion context secondary sm" data-cx-accordion>
  ...
</div>

<div class="accordion context alternate sm" data-cx-accordion>
  ...
</div>

Styles

Add a context style class, .solid, .smooth or .outline, next to the color class to change how the context color is applied.

Accordion Item #1

This is the first item's body, shown by default. It will automatically close when another item is opened by clicking its summary element.

Accordion Item #2

This is the second item's body. It is hidden by default and will open when its summary element is clicked.

Accordion Item #3

This is the third item's body. It is hidden by default and will open when its summary element is clicked.

Accordion Item #1

This is the first item's body, shown by default. It will automatically close when another item is opened by clicking its summary element.

Accordion Item #2

This is the second item's body. It is hidden by default and will open when its summary element is clicked.

Accordion Item #3

This is the third item's body. It is hidden by default and will open when its summary element is clicked.

Accordion Item #1

This is the first item's body, shown by default. It will automatically close when another item is opened by clicking its summary element.

Accordion Item #2

This is the second item's body. It is hidden by default and will open when its summary element is clicked.

Accordion Item #3

This is the third item's body. It is hidden by default and will open when its summary element is clicked.

Accordion Item #1

This is the first item's body, shown by default. It will automatically close when another item is opened by clicking its summary element.

Accordion Item #2

This is the second item's body. It is hidden by default and will open when its summary element is clicked.

Accordion Item #3

This is the third item's body. It is hidden by default and will open when its summary element is clicked.

HTML
<div class="accordion context primary sm" data-cx-accordion>
  ...
</div>

<div class="accordion context primary solid sm" data-cx-accordion>
  ...
</div>

<div class="accordion context primary smooth sm" data-cx-accordion>
  ...
</div>

<div class="accordion context primary outline sm" data-cx-accordion>
  ...
</div>

Accessibility

The native <details> and <summary> elements provide the keyboard interaction, the focus handling and the expanded state of each item without additional JavaScript or ARIA attributes. The <summary> is exposed as a disclosure button that Enter and Space toggle.

Heading semantics

A heading placed inside <summary> names the disclosure button, but its level is not exposed in the document outline.

HTML
<details>
  <summary>
    <h3 class="accordion-title">Accordion Item #1</h3>
  </summary>
  <div class="accordion-body">
    <!-- Content -->
  </div>
</details>

Screen readers announce the header as a disclosure button with the heading text as its accessible name, and the browser derives the expanded state from the open attribute. Inside a button, heading semantics are absorbed into the button role, so accordion headers are reachable through button and form-control navigation but not through heading shortcuts (the H key in NVDA, JAWS, or VoiceOver).

When heading-outline navigation is a hard requirement, the WAI-ARIA APG accordion pattern uses <h3><button> markup that participates in both heading and button navigation, at the cost of abandoning the native <details> element and managing the state in JavaScript.

JavaScript API

The Accordion plugin animates items as they open and close and fires events around each transition. Chassis JS ships as an ES module — import the Accordion class:

JavaScript
import { Accordion } from '@chassis-ui/css'

Triggers

The data-cx-accordion attribute on the wrapper enables the plugin for its direct <details> children. An instance is created for an item, and for the items that share its name, on the first click inside it:

HTML
<div class="accordion" data-cx-accordion>
  <details name="faq">...</details>
  <details name="faq">...</details>
</div>

Initialization

Each instance belongs to one <details> element and watches its open attribute. Create the instances up front when items are opened from a script before any click, so that the first change is animated too:

JavaScript
const instances = [...document.querySelectorAll('[data-cx-accordion] > details')]
  .map(element => Accordion.getOrCreateInstance(element))

The open attribute stays the source of truth: set the open property of the <details> element to open or close an item, and its instance animates the change.

JavaScript
document.querySelector('#shippingItem').open = true

Methods

The plugin exposes methods to manage the instance of an item:

MethodDescription
disposeDestroys the instance and stops watching the open attribute.
getInstanceStatic — returns the instance bound to a <details> element, or null.
getOrCreateInstanceStatic — returns the instance bound to a <details> element, or creates one.

Events

All events fire on the <details> element. The browser has already toggled the item when open.cx.accordion or close.cx.accordion fires, so calling event.preventDefault() on one of them skips the transition and the event that follows it, but does not revert the state.

EventDescription
open.cx.accordionFires when an item starts to open.
opened.cx.accordionFires when the opening transition has ended.
close.cx.accordionFires when an item starts to close.
closed.cx.accordionFires when the closing transition has ended.
JavaScript
const item = document.querySelector('#shippingItem')

item.addEventListener('opened.cx.accordion', () => {
  // The item is fully expanded
})

CSS

This component can be customized at both runtime (via custom properties) and compile time (via Sass variables).

Custom properties

The Accordion component exposes CSS custom properties to control its appearance at runtime. They follow the cascading variables pattern, inheriting values from a context class or any parent element.

--cx-border-color: var(--cx-accordion-border-color, var(--cx-default-border-subtle));
--cx-border-width: var(--cx-accordion-border-width, var(--cx-border-width-md));
--cx-border-radius: var(--cx-accordion-border-radius, var(--cx-border-radius-md));
--cx-inner-border-radius: var(--cx-accordion-inner-border-radius, calc(var(--cx-border-radius) - var(--cx-border-width)));
--cx-transition: var(--cx-accordion-transition, height 0.35s ease);
--cx-item-fg-color: var(--cx-accordion-item-fg-color, var(--cx-default-fg-main));
--cx-item-bg-color: var(--cx-accordion-item-bg-color, var(--cx-default-bg-main));
--cx-title-padding-y: var(--cx-accordion-title-padding-y, 0.75rem);
--cx-title-padding-x: var(--cx-accordion-title-padding-x, 1rem);
--cx-title-gap: var(--cx-accordion-title-gap, 1rem);
--cx-title-fg-color: var(--cx-accordion-title-fg-color, var(--cx-default-fg-main));
--cx-title-bg-color: var(--cx-accordion-title-bg-color, var(--cx-default-bg-main));
--cx-title-fg-active: var(--cx-accordion-title-fg-active, var(--cx-default-fg-main));
--cx-title-bg-active: var(--cx-accordion-title-bg-active, var(--cx-default-bg-main));
--cx-title-font-family: var(--cx-accordion-title-font-family, var(--cx-font-family-ui));
--cx-title-font-size: var(--cx-accordion-title-font-size, var(--cx-font-size-ui-md));
--cx-title-font-weight: var(--cx-accordion-title-font-weight, var(--cx-font-weight-ui-strong));
--cx-title-line-height: var(--cx-accordion-title-line-height, var(--cx-line-height-ui-md));
--cx-title-transition: var(--cx-accordion-title-transition, color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out, border-radius 0.15s ease);
--cx-body-padding-t: var(--cx-accordion-body-padding-t, 0.25rem);
--cx-body-padding-b: var(--cx-accordion-body-padding-b, 1.75rem);
--cx-body-padding-s: var(--cx-accordion-body-padding-s, 3.5rem);
--cx-body-padding-e: var(--cx-accordion-body-padding-e, 1rem);
--cx-body-font-family: var(--cx-accordion-body-font-family, var(--cx-font-family-ui));
--cx-body-font-size: var(--cx-accordion-body-font-size, var(--cx-font-size-ui-md));
--cx-body-font-weight: var(--cx-accordion-body-font-weight, var(--cx-font-weight-ui-normal));
--cx-body-line-height: var(--cx-accordion-body-line-height, var(--cx-line-height-ui-md));
--cx-caret-icon: var(--cx-accordion-caret-icon, url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' fill='currentcolor' viewBox='0 0 24 24'%3e%3cpath d='m11.121 16.629-7.5-7.5a1.205 1.205 0 0 1 0-1.758 1.205 1.205 0 0 1 1.758 0l6.64 6.602 6.602-6.602a1.205 1.205 0 0 1 1.758 0c.508.469.508 1.29 0 1.758l-7.5 7.5a1.205 1.205 0 0 1-1.758 0Z'/%3e%3c/svg%3e"));
--cx-caret-size: var(--cx-accordion-caret-size, 1.5rem);
--cx-caret-idle-color: var(--cx-accordion-caret-idle-color, var(--cx-default-fg-main));
--cx-caret-active-color: var(--cx-accordion-caret-active-color, var(--cx-default-icon-main));
--cx-caret-transform: var(--cx-accordion-caret-transform, rotate(-180deg));
--cx-caret-transition: var(--cx-accordion-caret-transition, transform 0.2s ease-in-out);

Sass variables

The Accordion component uses Sass variables in scss/config/_defaults.scss to define its defaults; they are also exposed as CSS custom properties using the --cx- prefix for runtime override — $variable-name becomes --cx-variable-name. See the component anatomy page.

$accordion-inner-border-radius:         calc(var(--border-radius) - var(--border-width));
$accordion-transition:                  $transition-collapse;
$accordion-title-transition:            $button-transition, border-radius .15s ease;
$accordion-caret-transition:            $caret-transition;
$accordion-caret-transform:             rotate(-180deg);
$accordion-focus-ring-offset:           0px;
// Accordion context variables are not exposed as CSS variables.
$accordion-item-fg-color-context:       var(--fg-main);
$accordion-item-bg-color-context:       var(--bg-main);
$accordion-title-fg-color-context:      var(--fg-main);
$accordion-title-bg-color-context:      var(--bg-main);
$accordion-title-fg-active-context:     var(--fg-main);
$accordion-title-bg-active-context:     var(--bg-main);
$accordion-caret-idle-context:          var(--icon-subtle);
$accordion-caret-active-context:        var(--icon-main);
$accordion-border-color-context:        var(--border-subtle);

Design tokens

The Accordion component consumes design tokens from Chassis Tokens with the $cx- prefix. — See the design tokens page.

// Font
$accordion-title-font:                    $cx-font-accordion-medium-title;
$accordion-body-font:                     $cx-font-accordion-medium-body;
$accordion-large-title-font:              $cx-font-accordion-large-title;
$accordion-large-body-font:               $cx-font-accordion-large-body;
$accordion-small-title-font:              $cx-font-accordion-small-title;
$accordion-small-body-font:               $cx-font-accordion-small-body;
// Color
$accordion-item-fg-color:                 $cx-color-accordion-item-fg-color;
$accordion-item-bg-color:                 $cx-color-accordion-item-bg-color;
$accordion-title-fg-color:                $cx-color-accordion-title-fg-idle;
$accordion-title-bg-color:                $cx-color-accordion-title-bg-idle;
$accordion-title-fg-active:               $cx-color-accordion-title-fg-active;
$accordion-title-bg-active:               $cx-color-accordion-title-bg-active;
$accordion-caret-idle-color:              $cx-color-accordion-indicator-idle;
$accordion-caret-active-color:            $cx-color-accordion-indicator-active;
$accordion-border-color:                  $cx-color-accordion-border-main;
// Size
$accordion-caret-size:                    $cx-size-accordion-medium-indicator;
$accordion-large-caret-size:              $cx-size-accordion-large-indicator;
$accordion-small-caret-size:              $cx-size-accordion-small-indicator;
// Spacing
$accordion-title-padding-y:               $cx-space-accordion-medium-title-padding-y;
$accordion-title-padding-x:               $cx-space-accordion-medium-title-padding-x;
$accordion-title-gap:                     $cx-space-accordion-medium-gap;
$accordion-body-padding-t:                $cx-space-accordion-medium-body-padding-t;
$accordion-body-padding-b:                $cx-space-accordion-medium-body-padding-b;
$accordion-body-padding-s:                $cx-space-accordion-medium-body-padding-s;
$accordion-body-padding-e:                $cx-space-accordion-medium-body-padding-e;
$accordion-large-title-padding-y:         $cx-space-accordion-large-title-padding-y;
$accordion-large-title-padding-x:         $cx-space-accordion-large-title-padding-x;
$accordion-large-title-gap:               $cx-space-accordion-large-gap;
$accordion-large-body-padding-t:          $cx-space-accordion-large-body-padding-t;
$accordion-large-body-padding-b:          $cx-space-accordion-large-body-padding-b;
$accordion-large-body-padding-s:          $cx-space-accordion-large-body-padding-s;
$accordion-large-body-padding-e:          $cx-space-accordion-large-body-padding-e;
$accordion-small-title-padding-y:         $cx-space-accordion-small-title-padding-y;
$accordion-small-title-padding-x:         $cx-space-accordion-small-title-padding-x;
$accordion-small-title-gap:               $cx-space-accordion-small-gap;
$accordion-small-body-padding-t:          $cx-space-accordion-small-body-padding-t;
$accordion-small-body-padding-b:          $cx-space-accordion-small-body-padding-b;
$accordion-small-body-padding-s:          $cx-space-accordion-small-body-padding-s;
$accordion-small-body-padding-e:          $cx-space-accordion-small-body-padding-e;
// Borders
$accordion-border-width:                  $cx-border-width-accordion-main;
$accordion-border-radius:                 $cx-border-radius-accordion-main;
// Icon
$accordion-caret-icon:                    $cx-icon-accordion-indicator;