Accordions ​

The accordion component provides a set of classes for grouping content into panels that readers can expand or collapse.

Base classes ​

Inside .accordion, use an .accordion-item for each panel. Start each item with an .accordion-item-header containing a heading with the .accordion-item-title class. The heading holds the .accordion-item-toggle button.

Place .accordion-item-content after the header. Put the main content in .accordion-item-body and add an .accordion-item-footer if you need room for extra details.

For an item that starts expanded, add .show to the item and set aria-expanded="true" on its button. For an item that starts collapsed, use .hide and aria-expanded="false". Once the accordion is initialized, readers can toggle a panel by clicking its button or pressing Enter or Space while the button has focus.

Initialization ​

Run the accordion generator after the markup is in the DOM. The generator links each toggle to its panel and updates aria-expanded as the panel opens or closes.

js
import generateAccordions from "@graupl/core/accordion/generator";

generateAccordions();

Expand and collapse all ​

To let readers open or close every panel at once, put the buttons in an .accordion-control-container. Give both buttons the .accordion-control class, then add .expand-all to the button that opens the panels and .collapse-all to the one that closes them.

Options ​

By default, readers can expand multiple panels and collapse all of them. To limit the accordion to one expanded panel at a time, set allowExpandMultiple to false.

Set allowCollapseAll to false to keep the last expanded panel from closing. Start with at least one panel expanded when using this setting. If you also limit the accordion to one expanded panel, start with exactly one.

Set optionalKeySupport to true so readers can use the Up and Down arrows, Home, and End to move between item toggles.

Pass these options to the generator to apply them to the accordions it initializes. To configure an individual accordion, set data-graupl-accordion-options on the .accordion element. The attribute takes JSON, such as data-graupl-accordion-options='{"optionalKeySupport":true}'.

js
generateAccordions({
  options: {
    allowExpandMultiple: false,
    allowCollapseAll: false,
    optionalKeySupport: true,
  },
});

Variants ​

By default, no theme variants are generated.

If you are compiling your own version of Graupl, you can set the accordion module’s $themeable variable to true to generate the .primary, .secondary, and .tertiary variants. Add the variant class to .accordion to style the whole accordion, or to an element inside it to style that part separately.

Custom Properties ​

The following custom properties can be used to customize the accordion component:

PropertyDescriptionDefault Value
--graupl-accordion-padding-xThe horizontal padding of the accordion.var(--graupl-spacer-0)
--graupl-accordion-padding-yThe vertical padding of the accordion.var(--graupl-spacer-0)
--graupl-accordion-paddingThe padding of the accordion.var(--graupl-accordion-padding-y) var(--graupl-accordion-padding-x)
--graupl-accordion-column-gapThe column gap of the accordion.var(--graupl-spacer-0)
--graupl-accordion-row-gapThe row gap of the accordion.var(--graupl-spacer-0)
--graupl-accordion-gapThe gap of the accordion.var(--graupl-accordion-row-gap) var(--graupl-accordion-column-gap)
--graupl-accordion-colorThe text color of the accordion.var(--graupl-color)
--graupl-accordion-backgroundThe background of the accordion.var(--graupl-background)
--graupl-accordion-border-colorThe border color of the accordion.var(--graupl-accordion-color)
--graupl-accordion-item-colorThe text color of the accordion item.var(--graupl-accordion-color)
--graupl-accordion-item-backgroundThe background of the accordion item.var(--graupl-accordion-background)
--graupl-accordion-item-border-colorThe border color of the accordion item.var(--graupl-accordion-border-color)
--graupl-accordion-item-border-top-left-radiusThe border top left radius of the accordion item.var(--graupl-border-top-left-radius)
--graupl-accordion-item-border-top-right-radiusThe border top right radius of the accordion item.var(--graupl-border-top-right-radius)
--graupl-accordion-item-border-bottom-right-radiusThe border bottom right radius of the accordion item.var(--graupl-border-bottom-right-radius)
--graupl-accordion-item-border-bottom-left-radiusThe border bottom left radius of the accordion item.var(--graupl-border-bottom-left-radius)
--graupl-accordion-item-border-radiusThe border radius of the accordion item.var(--graupl-accordion-item-border-top-left-radius) var(--graupl-accordion-item-border-top-right-radius) var(--graupl-accordion-item-border-bottom-right-radius) var(--graupl-accordion-item-border-bottom-left-radius)
--graupl-accordion-item-border-top-widthThe border top width of the accordion item.var(--graupl-border-top-width)
--graupl-accordion-item-border-right-widthThe border right width of the accordion item.var(--graupl-border-right-width)
--graupl-accordion-item-border-bottom-widthThe border bottom width of the accordion item.var(--graupl-border-bottom-width)
--graupl-accordion-item-border-left-widthThe border left width of the accordion item.var(--graupl-border-left-width)
--graupl-accordion-item-border-widthThe border width of the accordion item.var(--graupl-accordion-item-border-top-width) var(--graupl-accordion-item-border-right-width) var(--graupl-accordion-item-border-bottom-width) var(--graupl-accordion-item-border-left-width)
--graupl-accordion-item-border-top-styleThe border top style of the accordion item.var(--graupl-border-top-style)
--graupl-accordion-item-border-right-styleThe border right style of the accordion item.var(--graupl-border-right-style)
--graupl-accordion-item-border-bottom-styleThe border bottom style of the accordion item.var(--graupl-border-bottom-style)
--graupl-accordion-item-border-left-styleThe border left style of the accordion item.var(--graupl-border-left-style)
--graupl-accordion-item-border-styleThe border style of the accordion item.var(--graupl-accordion-item-border-top-style) var(--graupl-accordion-item-border-right-style) var(--graupl-accordion-item-border-bottom-style) var(--graupl-accordion-item-border-left-style)
--graupl-accordion-item-header-padding-xThe horizontal padding of the item header.var(--graupl-spacer-0)
--graupl-accordion-item-header-padding-yThe vertical padding of the item header.var(--graupl-spacer-0)
--graupl-accordion-item-header-paddingThe padding of the item header.var(--graupl-accordion-item-header-padding-y) var(--graupl-accordion-item-header-padding-x)
--graupl-accordion-item-header-marginThe margin of the item header.calc(-1 * min(var(--graupl-accordion-item-border-top-width), var(--graupl-accordion-item-border-bottom-width), var(--graupl-accordion-item-border-left-width), var(--graupl-accordion-item-border-right-width)))
--graupl-accordion-item-title-padding-xThe horizontal padding of the item title.var(--graupl-spacer-0)
--graupl-accordion-item-title-padding-yThe vertical padding of the item title.var(--graupl-spacer-0)
--graupl-accordion-item-title-paddingThe padding of the item title.var(--graupl-accordion-item-title-padding-y) var(--graupl-accordion-item-title-padding-x)
--graupl-accordion-item-title-margin-xThe horizontal margin of the item title.var(--graupl-spacer-0)
--graupl-accordion-item-title-margin-yThe vertical margin of the item title.var(--graupl-spacer-0)
--graupl-accordion-item-title-marginThe margin of the item title.var(--graupl-accordion-item-title-margin-y) var(--graupl-accordion-item-title-margin-x)
--graupl-accordion-item-title-colorThe text color of the item title.var(--graupl-accordion-item-color)
--graupl-accordion-item-title-backgroundThe background of the item title.var(--graupl-accordion-item-background)
--graupl-accordion-item-title-border-colorThe border color of the item title.var(--graupl-accordion-item-border-color)
--graupl-accordion-item-title-font-sizeThe font size of the item title.var(--graupl-h5-font-size)
--graupl-accordion-item-title-font-weightThe font weight of the item title.var(--graupl-h5-font-weight)
--graupl-accordion-item-title-font-familyThe font family of the item title.var(--graupl-h5-font-family)
--graupl-accordion-item-title-line-heightThe line height of the item title.var(--graupl-h5-line-height)
--graupl-accordion-item-content-colorThe text color of the item panel.var(--graupl-accordion-item-color)
--graupl-accordion-item-content-backgroundThe background of the item panel.var(--graupl-accordion-item-background)
--graupl-accordion-item-content-padding-xThe horizontal padding of the item panel.var(--graupl-spacer-5)
--graupl-accordion-item-content-padding-yThe vertical padding of the item panel.var(--graupl-spacer-5)
--graupl-accordion-item-content-paddingThe padding of the item panel.var(--graupl-accordion-item-content-padding-y) var(--graupl-accordion-item-content-padding-x)
--graupl-accordion-item-content-column-gapThe column gap of the item panel.var(--graupl-spacer-3)
--graupl-accordion-item-content-row-gapThe row gap of the item panel.var(--graupl-spacer-0)
--graupl-accordion-item-content-gapThe gap of the item panel.var(--graupl-accordion-item-content-row-gap) var(--graupl-accordion-item-content-column-gap)
--graupl-accordion-item-body-padding-xThe horizontal padding of the item body.var(--graupl-spacer-0)
--graupl-accordion-item-body-padding-yThe vertical padding of the item body.var(--graupl-spacer-0)
--graupl-accordion-item-body-paddingThe padding of the item body.var(--graupl-accordion-item-body-padding-y) var(--graupl-accordion-item-body-padding-x)
--graupl-accordion-item-footer-padding-xThe horizontal padding of the item footer.var(--graupl-spacer-0)
--graupl-accordion-item-footer-padding-yThe vertical padding of the item footer.var(--graupl-spacer-0)
--graupl-accordion-item-footer-paddingThe padding of the item footer.var(--graupl-accordion-item-footer-padding-y) var(--graupl-accordion-item-footer-padding-x)
--graupl-accordion-item-content-transformThe transform of the item panel.translateY(-100%)
--graupl-accordion-item-content-open-transformThe transform of the expanded item panel.translateY(0)
--graupl-accordion-item-toggle-padding-xThe horizontal padding of the item toggle.var(--graupl-button-padding-x)
--graupl-accordion-item-toggle-padding-yThe vertical padding of the item toggle.var(--graupl-button-padding-y)
--graupl-accordion-item-toggle-paddingThe padding of the item toggle.var(--graupl-accordion-item-toggle-padding-y) var(--graupl-accordion-item-toggle-padding-x)
--graupl-accordion-item-toggle-transformThe transform of the item toggle.none
--graupl-accordion-item-toggle-visited-transformThe transform of the visited item toggle.var(--graupl-accordion-item-toggle-transform)
--graupl-accordion-item-toggle-focus-transformThe transform of the focused item toggle.var(--graupl-accordion-item-toggle-transform)
--graupl-accordion-item-toggle-hover-transformThe transform of the hovered item toggle.var(--graupl-accordion-item-toggle-transform)
--graupl-accordion-item-toggle-active-transformThe transform of the active item toggle.none
--graupl-accordion-item-toggle-disabled-transformThe transform of the disabled item toggle.none
--graupl-accordion-item-toggle-pseudo-transformThe transform of the toggle indicator.none
--graupl-accordion-item-toggle-pseudo-open-transformThe transform of the expanded toggle indicator.rotate(-180deg)
--graupl-accordion-transition-durationThe transition duration of the accordion.var(--graupl-transition-duration-slow)
--graupl-accordion-transition-timing-functionThe transition timing function of the accordion.var(--graupl-transition-timing-function)
--graupl-accordion-item-transitionThe transition of the accordion item.height var(--graupl-accordion-transition-duration) var(--graupl-accordion-transition-timing-function)
--graupl-accordion-item-transition-reduced-motionThe transition of the accordion item when reduced motion is enabled.none
--graupl-accordion-item-toggle-pseudo-transitionThe transition of the toggle indicator.transform var(--graupl-accordion-transition-duration) var(--graupl-accordion-transition-timing-function)
--graupl-accordion-item-toggle-pseudo-transition-reduced-motionThe transition of the toggle indicator when reduced motion is enabled.none
--graupl-accordion-item-content-transitionThe transition of the item panel.opacity var(--graupl-accordion-transition-duration) var(--graupl-accordion-transition-timing-function) transform var(--graupl-accordion-transition-duration) var(--graupl-accordion-transition-timing-function)
--graupl-accordion-item-content-transition-reduced-motionThe transition of the item panel when reduced motion is enabled.opacity var(--graupl-accordion-transition-duration) var(--graupl-accordion-transition-timing-function)
--graupl-accordion-item-toggle-transitionThe transition of the item toggle.background var(--graupl-accordion-transition-duration) var(--graupl-accordion-transition-timing-function), color var(--graupl-accordion-transition-duration) var(--graupl-accordion-transition-timing-function), transform var(--graupl-accordion-transition-duration) var(--graupl-accordion-transition-timing-function)
--graupl-accordion-item-toggle-transition-reduced-motionThe transition of the item toggle when reduced motion is enabled.background var(--graupl-accordion-transition-duration) var(--graupl-accordion-transition-timing-function), color var(--graupl-accordion-transition-duration) var(--graupl-accordion-transition-timing-function)
--graupl-accordion-item-toggle-colorThe text color of the item toggle.var(--graupl-accordion-item-color)
--graupl-accordion-item-toggle-visited-colorThe text color of the visited item toggle.var(--graupl-accordion-item-toggle-color)
--graupl-accordion-item-toggle-focus-colorThe text color of the focused item toggle.var(--graupl-accordion-item-toggle-color)
--graupl-accordion-item-toggle-hover-colorThe text color of the hovered item toggle.var(--graupl-accordion-background)
--graupl-accordion-item-toggle-active-colorThe text color of the active item toggle.var(--graupl-accordion-item-toggle-hover-color)
--graupl-accordion-item-toggle-disabled-colorThe text color of the disabled item toggle.var(--graupl-theme-active--primary--200)
--graupl-accordion-item-toggle-backgroundThe background of the item toggle.var(--graupl-accordion-background)
--graupl-accordion-item-toggle-visited-backgroundThe background of the visited item toggle.var(--graupl-accordion-item-toggle-background)
--graupl-accordion-item-toggle-focus-backgroundThe background of the focused item toggle.var(--graupl-accordion-item-toggle-background)
--graupl-accordion-item-toggle-hover-backgroundThe background of the hovered item toggle.var(--graupl-accordion-color)
--graupl-accordion-item-toggle-active-backgroundThe background of the active item toggle.var(--graupl-accordion-item-toggle-hover-background)
--graupl-accordion-item-toggle-disabled-backgroundThe background of the disabled item toggle.var(--graupl-accordion-background)
--graupl-accordion-item-toggle-border-colorThe border color of the item toggle.var(--graupl-accordion-item-border-color)
--graupl-accordion-item-toggle-visited-border-colorThe border color of the visited item toggle.var(--graupl-accordion-item-toggle-border-color)
--graupl-accordion-item-toggle-focus-border-colorThe border color of the focused item toggle.var(--graupl-accordion-item-toggle-border-color)
--graupl-accordion-item-toggle-hover-border-colorThe border color of the hovered item toggle.var(--graupl-accordion-item-border-color)
--graupl-accordion-item-toggle-active-border-colorThe border color of the active item toggle.var(--graupl-accordion-item-toggle-hover-border-color)
--graupl-accordion-item-toggle-disabled-border-colorThe border color of the disabled item toggle.var(--graupl-theme-active--primary--200)
--graupl-accordion-control-colorThe text color of the bulk control.var(--graupl-accordion-color)
--graupl-accordion-control-visited-colorThe text color of the visited bulk control.var(--graupl-accordion-control-color)
--graupl-accordion-control-focus-colorThe text color of the focused bulk control.var(--graupl-accordion-control-color)
--graupl-accordion-control-hover-colorThe text color of the hovered bulk control.var(--graupl-accordion-background)
--graupl-accordion-control-active-colorThe text color of the active bulk control.var(--graupl-accordion-control-hover-color)
--graupl-accordion-control-disabled-colorThe text color of the disabled bulk control.var(--graupl-theme-active--primary--200)
--graupl-accordion-control-backgroundThe background of the bulk control.var(--graupl-accordion-background)
--graupl-accordion-control-visited-backgroundThe background of the visited bulk control.var(--graupl-accordion-control-background)
--graupl-accordion-control-focus-backgroundThe background of the focused bulk control.var(--graupl-accordion-control-background)
--graupl-accordion-control-hover-backgroundThe background of the hovered bulk control.var(--graupl-accordion-color)
--graupl-accordion-control-active-backgroundThe background of the active bulk control.var(--graupl-accordion-control-hover-background)
--graupl-accordion-control-disabled-backgroundThe background of the disabled bulk control.var(--graupl-accordion-background)
--graupl-accordion-control-border-colorThe border color of the bulk control.var(--graupl-accordion-border-color)
--graupl-accordion-control-visited-border-colorThe border color of the visited bulk control.var(--graupl-accordion-control-border-color)
--graupl-accordion-control-focus-border-colorThe border color of the focused bulk control.var(--graupl-accordion-control-border-color)
--graupl-accordion-control-hover-border-colorThe border color of the hovered bulk control.var(--graupl-accordion-border-color)
--graupl-accordion-control-active-border-colorThe border color of the active bulk control.var(--graupl-accordion-control-hover-border-color)
--graupl-accordion-control-disabled-border-colorThe border color of the disabled bulk control.var(--graupl-theme-active--primary--200)
--graupl-accordion-control-container-padding-xThe horizontal padding of the bulk control container.0
--graupl-accordion-control-container-padding-yThe vertical padding of the bulk control container.0
--graupl-accordion-control-container-paddingThe padding of the bulk control container.var(--graupl-accordion-control-container-padding-y) var(--graupl-accordion-control-container-padding-x)
--graupl-accordion-control-container-column-gapThe column gap of the bulk control container.var(--graupl-spacer-3)
--graupl-accordion-control-container-row-gapThe row gap of the bulk control container.var(--graupl-spacer-3)
--graupl-accordion-control-container-gapThe gap of the bulk control container.var(--graupl-accordion-control-container-row-gap) var(--graupl-accordion-control-container-column-gap)

Sass variables ​

The following Sass variables can be used to customize the generation of the accordion component:

VariableDescriptionDefault Value
$selector-baseThe selector base for the component."."
$modifier-selector-baseThe selector base for component modifiers."."
$generate-base-theme-mapWhether to include the default accordion theme mappings.true
$themeableWhether to generate accordion theme variants.false
$accordion-selector-baseThe selector base for the accordion."."
$accordion-selectorThe selector for the accordion."accordion"
$accordion-theme-selector-baseThe selector base for the accordion theme."."
$accordion-theme-selector-prefixThe selector prefix for the accordion theme.""
$accordion-item-selector-baseThe selector base for the accordion item."."
$accordion-item-selectorThe selector for the accordion item."accordion-item"
$accordion-item-header-selector-baseThe selector base for the accordion item header."."
$accordion-item-header-selectorThe selector for the accordion item header."accordion-item-header"
$accordion-item-title-selector-baseThe selector base for the accordion item title."."
$accordion-item-title-selectorThe selector for the accordion item title."accordion-item-title"
$accordion-item-toggle-selector-baseThe selector base for the accordion item toggle."."
$accordion-item-toggle-selectorThe selector for the accordion item toggle."accordion-item-toggle"
$accordion-item-content-selector-baseThe selector base for the accordion item content."."
$accordion-item-content-selectorThe selector for the accordion item content."accordion-item-content"
$accordion-item-body-selector-baseThe selector base for the accordion item body."."
$accordion-item-body-selectorThe selector for the accordion item body."accordion-item-body"
$accordion-item-footer-selector-baseThe selector base for the accordion item footer."."
$accordion-item-footer-selectorThe selector for the accordion item footer."accordion-item-footer"
$accordion-item-open-selector-baseThe selector base for the expanded item."."
$accordion-item-open-selectorThe selector for the expanded item."show"
$accordion-item-close-selector-baseThe selector base for the collapsed item."."
$accordion-item-close-selectorThe selector for the collapsed item."hide"
$accordion-item-transition-selector-baseThe selector base for the transitioning item."."
$accordion-item-transition-selectorThe selector for the transitioning item."transitioning"
$accordion-item-toggle-pseudo-selectorThe pseudo-element selector for the toggle indicator."after"
$accordion-control-selector-baseThe selector base for the accordion control."."
$accordion-control-selectorThe selector for the accordion control."accordion-control"
$accordion-control-container-selector-baseThe selector base for the accordion control container."."
$accordion-control-container-selectorThe selector for the accordion control container."accordion-control-container"
$accordion-item-toggle-initial-transformThe initial transform of the accordion item toggle.none
$accordion-item-toggle-final-transformThe transform of the item toggle while pressed.none
$accordion-item-toggle-disabled-transformThe disabled transform of the accordion item toggle.none
$accordion-item-toggle-pseudo-initial-transformThe initial transform of the toggle indicator.none
$accordion-item-toggle-pseudo-contentThe content of the toggle indicator."▼"
$accordion-item-content-initial-transformThe transform of the panel when collapsed.translateY(-100%)
$accordion-item-content-final-transformThe transform of the panel when expanded.translateY(0)
$accordion-theme-mappingsA map of properties and color shades used to generate all accordion variants.map.merge($-accordion-theme-mappings, $accordion-theme-mappings)
$accordion-theme-mapA map of all properties, colors, and color shades used to generate all accordion variants.map.deep-merge($-accordion-theme-map, $accordion-theme-map)