Accordion
On this page
Importing
Add rh-accordion to your page with this import statement:
<script type="module">
import '@rhds/elements/rh-accordion/rh-accordion.js';
</script>
Copy to Clipboard
Copied!
Wrap lines
Overflow lines
To learn more about installing RHDS elements on your site using an import map read our getting started docs.
Usage
<rh-accordion>
<!-- H2 tags will be removed on upgrade, rh-accordion-header will set the correct heading level internally using the header tag that wraps it -->
<h2><rh-accordion-header>Item One</rh-accordion-header></h2>
<rh-accordion-panel>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</rh-accordion-panel>
<h2><rh-accordion-header>Item Two</rh-accordion-header></h2>
<rh-accordion-panel>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</rh-accordion-panel>
<h2><rh-accordion-header>Item Three</rh-accordion-header></h2>
<rh-accordion-panel>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</rh-accordion-panel>
</rh-accordion>
<script type="module">
import '@rhds/elements/rh-accordion/rh-accordion.js';
</script>
Copy to Clipboard
Copied!
Wrap lines
Overflow lines
rh-accordion
An accordion is a stacked list of panels which allows users to expand or collapse information when selected. They feature panels that consist of a section text label and a caret icon that collapses or expands to reveal more information.
| Slot Name | Summary | Description |
|---|---|---|
[default]
|
Place the |
| Attribute | DOM Property | Description | Type | Default |
|---|---|---|---|---|
accents
|
undefined |
|
|
|
accents
|
accents |
Positions the accent slot content relative to the panel's title. The accent slot contains secondary information such as tags, badges, or other small elements.
Usage guidelines
|
|
|
large
|
large |
If this accordion uses large styles |
|
|
color-palette
|
colorPalette |
Color Palette for this accordion. |
|
|
expanded-index
|
expandedIndex |
Sets and reflects the currently expanded accordion 0-based indexes. Use commas to separate multiple indexes. |
|
|
| Method Name | Description |
|---|---|
hasChanged()
|
|
updateAccessibility()
|
Initialize the accordion by connecting headers and panels with aria controls and labels; set up the default disclosure state if not set by the author; and check the URL for default open |
toggle(index: number)
|
Accepts a 0-based index value (integer) for the set of accordion items to expand or collapse. |
expand(index: number, parentAccordion: RhAccordion)
|
Accepts a 0-based index value (integer) for the set of accordion items to expand. Accepts an optional parent accordion to search for headers and panels. |
expandAll()
|
Expands all accordion items. |
collapse(index: number)
|
Accepts a 0-based index value (integer) for the set of accordion items to collapse. |
collapseAll()
|
Collapses all accordion items. |
| Event Name | Description |
|---|---|
expand
|
when a panel expands |
collapse
|
when a panel collapses |
| Token | Summary | Copy |
|---|---|---|
--rh-color-text-primary
|
|
|
--rh-color-surface-lightest
|
|
|
--rh-color-surface-darkest
|
|
|
--rh-color-surface
|
|
|
--rh-font-size-body-text-md
|
|
|
--rh-font-size-body-text-lg
|
|
|
--rh-color-border-subtle
|
|
|
--rh-box-shadow-sm
|
|
rh-accordion-header
Accordion Header We expect the light DOM of the rh-accordion-header to be a heading level tag (h1, h2, h3, h4, h5, h6)
| Slot Name | Summary | Description |
|---|---|---|
[default]
|
panel's title text or heading content |
Contains the primary label that describes what content will be revealed when the panel expands. Title text should be written concisely (max 65 characters) so users know what to expect. Avoid writing titles that sound like calls to action - make it easy for users to understand the content within. Title text that is too long should be broken into separate sections, and text that is too vague may not help users understand the panel content. @see Title text in Guidelines documentation |
accents
|
decorations like icons or tags |
These elements will appear inline by default with the header title, between the header and the chevron (or after the chevron and header in disclosure mode). There is an option to set the accents placement to bottom |
| Attribute | DOM Property | Description | Type | Default |
|---|---|---|---|---|
expanded
|
expanded |
|
|
| Event Name | Description |
|---|---|
change
|
when the open panels change |
| Part Name | Summary | Description |
|---|---|---|
text
|
inline element containing the heading text or slotted heading content |
|
accents
|
container for accents within the header |
| Token | Summary | Copy |
|---|---|---|
--rh-space-lg
|
|
|
--rh-space-xl
|
|
|
--rh-border-width-sm
|
|
|
--rh-color-border-subtle
|
|
|
--rh-font-family-body-text
|
|
|
--rh-color-surface-lighter
|
|
|
--rh-color-surface-dark
|
|
|
--rh-color-text-primary
|
|
|
--rh-color-interactive-primary-default
|
|
|
--rh-border-width-lg
|
|
|
--rh-color-accent-brand
|
|
|
--rh-font-weight-body-text-medium
|
|
|
--rh-space-md
|
|
rh-accordion-panel
Accordion Panel
| Slot Name | Summary | Description |
|---|---|---|
[default]
|
The content of the accordion panel can be any basic markup including but not limited
to div, paragraph, or nested accordion panels. |
| Attribute | DOM Property | Description | Type | Default |
|---|---|---|---|---|
expanded
|
expanded |
Sets the initial visibility state of the panel content.
When Usage guidelines
By default, all panels are collapsed (expanded=false). Users expand panels by clicking the header, which animates the caret icon and reveals the content. |
|
|
| Part Name | Summary | Description |
|---|---|---|
container
|
main wrapper region that contains the panel content |
The container part represents the structural element that holds the panel's body content. It maintains the color scheme context to ensure proper text visibility and color contrast, and should match the color palette of the container it's in. This part defines the overall styling and boundaries for the panel's revealed content area. |
| Token | Summary | Copy |
|---|---|---|
--rh-space-xl
|
|
|
--rh-space-md
|
|
|
--rh-space-lg
|
|
|
--rh-color-border-subtle
|
|
|
--rh-border-width-lg
|
|
|
--rh-color-accent-brand
|
|
|
--rh-color-text-primary
|
|
Other libraries
To learn more about our other libraries, visit this page.
Feedback
To give feedback about anything on this page, contact us.