Accordion
Use accordions to organize related content in expandable sections. Explore examples with headings, borders, and multiple open panels.
This component requires the following JavaScript plugin:
Examples
Default
Mobile
320pxMobile Lg
480pxTablet
640pxDesktop
1024pxCongress shall make no law respecting an establishment of religion, or prohibiting the free exercise thereof; or abridging the freedom of speech, or of the press; or the right of the people peaceably to assemble, and to petition the Government for a redress of grievances.
A well regulated Militia, being necessary to the security of a free State, the right of the people to keep and bear Arms, shall not be infringed.
No Soldier shall, in time of peace be quartered in any house, without the consent of the Owner, nor in time of war, but in a manner to be prescribed by law.
With headings
Wrap each trigger in a heading when its panel represents a section of the page. Choose the heading level to fit the page structure, following the WAI-ARIA accordion pattern.
Mobile
320pxMobile Lg
480pxTablet
640pxDesktop
1024pxCongress shall make no law respecting an establishment of religion, or prohibiting the free exercise thereof; or abridging the freedom of speech, or of the press; or the right of the people peaceably to assemble, and to petition the Government for a redress of grievances.
Multiselectable
Mobile
320pxMobile Lg
480pxTablet
640pxDesktop
1024pxCongress shall make no law respecting an establishment of religion, or prohibiting the free exercise thereof; or abridging the freedom of speech, or of the press; or the right of the people peaceably to assemble, and to petition the Government for a redress of grievances.
A well regulated Militia, being necessary to the security of a free State, the right of the people to keep and bear Arms, shall not be infringed.
No Soldier shall, in time of peace be quartered in any house, without the consent of the Owner, nor in time of war, but in a manner to be prescribed by law.
Bordered
Mobile
320pxMobile Lg
480pxTablet
640pxDesktop
1024pxCongress shall make no law respecting an establishment of religion, or prohibiting the free exercise thereof; or abridging the freedom of speech, or of the press; or the right of the people peaceably to assemble, and to petition the Government for a redress of grievances.
A well regulated Militia, being necessary to the security of a free State, the right of the people to keep and bear Arms, shall not be infringed.
No Soldier shall, in time of peace be quartered in any house, without the consent of the Owner, nor in time of war, but in a manner to be prescribed by law.
Component API
Initialization
Run once after the accordion markup exists:
import { accordionInit } from '@uswds-tailwind/compat/accordion'
accordionInit()For an instance you can control, use Accordion.getOrCreateInstance(root, options). See shared instance methods.
Anatomy
Set authored attributes in your HTML. The component manages generated attributes. Types describe HTML attribute values.
root
Groups the accordion items.
| Attribute | Type | Description |
|---|---|---|
data-scope |
"accordion" |
Authored. Identifies the component scope. |
data-part |
"root" |
Authored. Identifies this part. |
data-multiple |
boolean-like attribute |
Authored. Allows several open panels. Bare attribute is true; omission or "false" is false. Overrides the multiple option, even when omitted. |
item
One panel, containing its trigger and content.
| Attribute | Type | Description |
|---|---|---|
data-part |
"item" |
Authored. Identifies this part. |
data-value |
string |
Authored. Required unique, nonempty item value; id is used as a fallback. |
data-state |
"open" | "closed" |
Authored. Use "open" to expand initially. In single-open mode, only the first marked item is used. defaultValue overrides these markers. |
data-state |
"open" | "closed" |
Generated. "open" or "closed"; use for styling. |
item-trigger
Toggles its panel. Place inside a heading when introducing a section.
| Attribute | Type | Description |
|---|---|---|
data-part |
"item-trigger" |
Authored. Identifies this part. |
data-state |
"open" | "closed" |
Generated. "open" or "closed"; use for styling. |
aria-expanded |
"true" | "false" |
Generated. Whether the content is expanded. |
aria-controls |
ID reference |
Generated. ID of the associated content. |
item-content
Panel content, inside the same item as its trigger.
| Attribute | Type | Description |
|---|---|---|
data-part |
"item-content" |
Authored. Identifies this part. |
data-state |
"open" | "closed" |
Generated. "open" or "closed"; use for styling. |
hidden |
boolean attribute |
Generated. Present when closed. |
Configuration
Pass these JavaScript options to the instance constructor or factory. Authored configuration attributes are read during construction.
| Option | Description |
|---|---|
defaultValue |
string[]. Initial expanded item values; overrides item state markers. |
value |
string[]. Controlled expanded values; takes precedence over defaultValue. |
id |
Instance identifier; defaults to the root ID or a generated value. |
ids |
Override the root ID, or pass itemTrigger(value) and itemContent(value) functions to generate item IDs. |
Methods
| Method | Returns | Description |
|---|---|---|
open(value) |
Promise<void> |
Requests expansion of the item. |
close(value) |
Promise<void> |
Requests collapse of the item. |
toggle(value) |
Promise<void> |
Requests the opposite expanded state. |
destroy() |
void |
Stops the instance and removes its lookup. Does not restore the original HTML. |
import { Accordion } from '@uswds-tailwind/compat/accordion'
const accordion = Accordion.getOrCreateInstance( '[data-scope="accordion"][data-part="root"]',)
await accordion.open('one')Pass the item’s data-value (or fallback id) as the value argument. Promises settle the queued update, not CSS transitions. When using controlled state, your application must supply the updated value.
See initialization and cleanup.
Callbacks
| Callback | Payload | When it runs |
|---|---|---|
onValueChange |
{ value: string[] } |
Expanded values change, or a controlled change is requested. |
Pass callbacks in instance options. They are JavaScript functions, not emitted DOM events.
Accessibility
- Supply meaningful button text and appropriate heading levels.
- Enter and Space activate the focused button.