Components · Layout and content

Collapsible

A collapsible is a row that opens and closes to show more content, used for FAQ lists and filters. The header can carry a descriptive text, icons, a toggle switch and a number badge. The content animates open.

How to add a collapsible to a page. The files are components/css/collapsible.css and components/js/collapsible.js.

Basic Usage

Link the shared stylesheet and the script once per page. Never copy the rules into a page.

StepWhat to do
1. Link<link rel="stylesheet" href="/components/css/collapsible.css"> and <script src="/components/js/collapsible.js"></script>. A switch needs switch.css, a number badge.css.
2. RowA .collapsible-wrap with a <button class="collapsible-item"> and a content element that follows it directly.
3. StateSet aria-expanded and aria-controls (the content’s id) on the button. The script updates aria-expanded.
4. ListStack several rows in one wrapper. They share the line between them.
5. Size, background and themeAdd collapsible-wrap--small, --boxed, --filled (a surface-raised-secondary header background) or --dark to the row.
6. OpenAdd collapsible-wrap--open and set max-height on the content to start open.

Collapsible

Copy the markup you need.

The markup has no motion. The open and close animation is set in Motion on Examples & Guidelines.


API

Classes

ClassUse
collapsible-wrapOne row with the line under it.
--open, --small, --boxed, --filled, --divider-top, --divider-bottom, --no-divider-bottom, --dark, --disabledModifiers on the row.
collapsible-itemThe header.
__left, __text, __line, __label, __info, __helper, __end, __chevronThe parts of the header.
collapsible-item__content, __bodyThe content. Animated with max-height.
__list, __row, __count, __support, __note, __moreContent patterns.

Script

FunctionUse
toggleCollapsible(header)Toggles the open class on the header’s parent, updates aria-expanded and sets max-height on the next sibling. It does nothing for a disabled row or for a click on a switch or a link in the header.

CSS variables

VariableUse
--co-easeThe easing of the open and close animation. Default var(--ease-standard).
--co-durationThe duration. Default var(--duration-fast-4).
--co-content-gapThe space from the header text to the content text. Default 24px, the same for every size.

Things to know

  • The content must be the next sibling of the header.
  • The last row’s line is hidden when the list is the last block in its section (not for a boxed row). Add collapsible-wrap--divider-bottom to keep it, for a section with one collapsible.
  • Boxed works in both sizes: add collapsible-wrap--boxed (Large) or collapsible-wrap--small collapsible-wrap--boxed (Small).
  • A header with a switch is a div, not a button. Prefer a row with a switch and no chevron.

CSS / Tailwind

The component is one CSS file and one script, shared by every page. Link them, never copy them. The code below is read from the files the page links, so it is always what you see.

CSS (components/css/collapsible.css)
JS (components/js/collapsible.js)