Accordion
An accordion consists of a vertically stacked list of headers, which can be pressed to reveal or hide associated sections of content.
<sl-accordion>
<sl-accordion-item summary="Discovering Dinosaurs: A Prehistoric Adventure">
Embark on a thrilling journey back in time to the age of dinosaurs...
</sl-accordion-item>
<sl-accordion-item summary="Geography Safari: Mapping Our World">
...
</sl-accordion-item>
<sl-accordion-item summary="Journey Through Ancient Civilizations">
...
</sl-accordion-item>
<sl-accordion-item summary="Math Magic - solving Puzzles with numbers">
...
</sl-accordion-item>
</sl-accordion>
When to use
Chunking information and reducing clutter
Reduce cognitive load for users by simplifying the interface. When you have a large amount of content, consider using accordions to hide non-essential information initially. Place detailed content within the accordion panel. Users can press on the accordion title to reveal the hidden information.
When not to use
When most items need to be opened
If users need to open the majority of accordion items, it’s better to reveal all the content instead of hiding some. Accordion components are designed to manage content visibility efficiently. If most items need to be expanded, consider alternative designs that display content upfront.
Anatomy
Item | Name | Description | Optional |
---|---|---|---|
1 | Header | Contains the section title and is control for revealing the panel. | No |
2 | Icon | Indicates if the panel is open or closed. | No |
3 | Panel | The section of content associated with an accordion header. | No |
Figma Options
With these options, you can tweak the appearance of the accordion in Figma. They are available in the Design Panel so you can compose the accordion to exactly fit the user experience need for the use case you are working on.
Item | Options | Description |
---|---|---|
Accordion open | all closed 01 02 03 04 05 06 07 08 09 10 all open | Determines which panel is open. |
Edit mode | boolean | Displays slot components for inserting the content of all panels. |
Show up (up to 01 including 10) | boolean | Determines if the item is visible. |
State (for every visible panel) | default hover active disabled | Determines the state of the item. |
Title (for every visible panel) | value | Displays the title of the item. |
<sl-accordion single>
<sl-accordion-item summary="Discovering Dinosaurs: A Prehistoric Adventure">
Embark on a thrilling journey back in time to the age of dinosaurs...
</sl-accordion-item>
<sl-accordion-item summary="Geography Safari: Mapping Our World">
...
</sl-accordion-item>
<sl-accordion-item summary="Journey Through Ancient Civilizations" disabled>
...
</sl-accordion-item>
<sl-accordion-item summary="Math Magic - solving Puzzles with numbers">
...
</sl-accordion-item>
</sl-accordion>
Accordion item API
Component has a range of properties to define the experience in different use cases.
Properties
Name | Attribute | Type | Default | Description |
---|---|---|---|---|
disabled | disabled | boolean | undefined | Whether the element is disabled. | |
open | open | boolean | undefined | Whether the details element is opened. | |
summary | summary | string | undefined | A text shown in the header - as a title of the accordion item. |
Methods
Name | Parameters | Return | Description |
---|---|---|---|
focus | options?: FocusOptions | void | This is a workaround for `delegatesFocus` not allowing you to select any text in the content of the accordion item. See https://issues.chromium.org/issues/40622041 |
toggle | force?: boolean | void | Toggles the component state between open or closed. If the `force` parameter is provided, the state will be set to the value of the parameter. |
Events
Name | Event type | Description |
---|---|---|
sl-toggle | SlToggleEvent<boolean> | Emits when the accordion item has been toggled. |
Slots
Name | Description |
---|---|
default | Body content for the accordion |
summary | Header content for the accordion; use this if the `summary` property is not enough |
CSS Parts
Name | Description |
---|---|
summary | Header element of the accordion-item |
panel | The body of the accordion-item |
Accordion API
Component has a range of properties to define the experience in different use cases.
Properties
Name | Attribute | Type | Default | Description |
---|---|---|---|---|
items | - | AccordionItem[] | undefined | The slotted accordion items. | |
single | single | boolean | undefined | Whether only one accordion item can be opened at once. By default, multiple accordion items can be opened. |
Slots
Name | Description |
---|---|
default | The place for multiple `<sl-accordion-item>` |
Alignment
The icons are left-aligned to improve the experience for users with low vision, as the expanded/collapsed indicator is closer to the accordion title.
Keyboard interactions
Each accordion is a tab stop. Space
or Enter
keys expand or collapse accordions, which are collapsed by default. Interactive elements within expanded accordions integrate into the tab order automatically.
WAI-ARIA
WAI-ARIA roles, states, and properties for an accordion provide essential information to assistive technologies and screen readers. They convey the accordion's role and additional properties to ensure accessibility and a better user experience for individuals using assistive technology.
Accordion item
Attribute | Value | Description | User supplied |
---|---|---|---|
aria-expanded | boolean | The header element (summary) contains aria-expanded attribute. When true , the associated content is shown; when false , it’s hidden. | no |
aria-controls | string | The header element (summary) contains aria-controls attribute. This id references the hidden content beneath it - the accordion panel content. It contains id of the panel element. | no |
role | 'region' | Role of the panel container. Creates a landmark region that contains the currently expanded accordion item's panel. | no |
aria-labelledby | string | Used to connect the content with accordion item summary (header). It contains id of the summary (header) element. | no |