Loading...
Skip to main content

Accordion

Build vertically collapsing accordions with native HTML <details> and <summary> elements.

The accordion uses native HTML <details> and <summary> elements, leveraging the name attribute to create exclusive accordions where only one item can be open at a time. This approach requires no JavaScript for core functionality and is fully accessible by default.

Example

Click the accordions below to expand/collapse the accordion content. Each <details> element shares the same name attribute value, creating an exclusive accordion where opening one item automatically closes the others.

To render an accordion that’s expanded by default, add the open attribute to the <details> element.

Accordion Item #1
This is the first item’s accordion body. It is shown by default because the open prop is present. Accordion items use native disclosure behavior without requiring JavaScript. Put any content inside AccordionBody.
Accordion Item #2
This is the second item’s accordion body. The name prop groups this with other accordion items. When you open this item, any other open item in the same group will close automatically.
Accordion Item #3
This is the third item’s accordion body. This exclusive accordion behavior is built into the browser—no Bootstrap JavaScript required. Set matching name props on the items.
<Accordion>
<AccordionItem
name="accordionExample"
open
>
<AccordionHeader>
{' '}Accordion Item #1{' '}
</AccordionHeader>
<AccordionBody>
<strong>
This is the first item’s accordion body.
</strong>
{' '}It is shown by default because the{' '}
<code>
open
</code>
{' '}prop is present. Accordion items use native disclosure behavior without requiring JavaScript. Put any content inside{' '}
<code>
AccordionBody
</code>
.{' '}
</AccordionBody>
</AccordionItem>
<AccordionItem name="accordionExample">
<AccordionHeader>
{' '}Accordion Item #2{' '}
</AccordionHeader>
<AccordionBody>
<strong>
This is the second item’s accordion body.
</strong>
{' '}The{' '}
<code>
name
</code>
{' '}prop groups this with other accordion items. When you open this item, any other open item in the same group will close automatically.{' '}
</AccordionBody>
</AccordionItem>
<AccordionItem name="accordionExample">
<AccordionHeader>
{' '}Accordion Item #3{' '}
</AccordionHeader>
<AccordionBody>
<strong>
This is the third item’s accordion body.
</strong>
{' '}This exclusive accordion behavior is built into the browser—no Bootstrap JavaScript required. Set matching{' '}
<code>
name
</code>
{' '}props on the items.{' '}
</AccordionBody>
</AccordionItem>
</Accordion>

The panel height animation needs interpolate-size. Browsers without it open and close the panel at once. See Transitions to change the timing or to remove it.

The animation effect depends on the prefers-reduced-motion media query. See the reduced motion accessibility guidance.

Variants

Set the theme prop on Accordion to apply a semantic theme color to its open items.

Accordion Item #1
This is the first item’s accordion body. It is shown by default because the open attribute is present. The native <details> element handles all the show/hide logic without any JavaScript. You can put any HTML content within the .accordion-body.
Accordion Item #2
This is the second item’s accordion body. The name attribute groups this with other accordion items. When you open this item, any other open item in the same group will close automatically.
Accordion Item #3
This is the third item’s accordion body. This exclusive accordion behavior is built into the browser—no Bootstrap JavaScript required. Just use matching name attributes on your <details> elements.
<Accordion theme="primary">
<AccordionItem
name="accordionExampleTheme"
open
>
<AccordionHeader>
{' '}Accordion Item #1{' '}
</AccordionHeader>
<AccordionBody>
<strong>
This is the first item’s accordion body.
</strong>
{' '}It is shown by default because the{' '}
<code>
open
</code>
{' '}attribute is present. The native{' '}
<code>
{`<details>`}
</code>
{' '}element handles all the show/hide logic without any JavaScript. You can put any HTML content within the{' '}
<code>
.accordion-body
</code>
.{' '}
</AccordionBody>
</AccordionItem>
<AccordionItem name="accordionExampleTheme">
<AccordionHeader>
{' '}Accordion Item #2{' '}
</AccordionHeader>
<AccordionBody>
<strong>
This is the second item’s accordion body.
</strong>
{' '}The{' '}
<code>
name
</code>
{' '}attribute groups this with other accordion items. When you open this item, any other open item in the same group will close automatically.{' '}
</AccordionBody>
</AccordionItem>
<AccordionItem name="accordionExampleTheme">
<AccordionHeader>
{' '}Accordion Item #3{' '}
</AccordionHeader>
<AccordionBody>
<strong>
This is the third item’s accordion body.
</strong>
{' '}This exclusive accordion behavior is built into the browser—no Bootstrap JavaScript required. Just use matching{' '}
<code>
name
</code>
{' '}attributes on your{' '}
<code>
{`<details>`}
</code>
{' '}elements.{' '}
</AccordionBody>
</AccordionItem>
</Accordion>

Small

Set size="sm" on Accordion for a more compact layout with tighter padding, a smaller border radius, and a smaller font size.

Accordion Item #1
This is the first item’s accordion body. The size="sm" size prop tightens up the padding, border radius, and font size for a more compact presentation.
Accordion Item #2
This is the second item’s accordion body. Everything is driven by CSS custom properties, so you can fine-tune the compact sizing to taste.
Accordion Item #3
This is the third item’s accordion body. Combine size="sm" with other props like flush as needed.
<Accordion size="sm">
<AccordionItem
name="accordionSmall"
open
>
<AccordionHeader>
{' '}Accordion Item #1{' '}
</AccordionHeader>
<AccordionBody>
<strong>
This is the first item’s accordion body.
</strong>
{' '}The{' '}
<code>
size="sm"
</code>
{' '}size prop tightens up the padding, border radius, and font size for a more compact presentation.{' '}
</AccordionBody>
</AccordionItem>
<AccordionItem name="accordionSmall">
<AccordionHeader>
{' '}Accordion Item #2{' '}
</AccordionHeader>
<AccordionBody>
<strong>
This is the second item’s accordion body.
</strong>
{' '}Everything is driven by CSS custom properties, so you can fine-tune the compact sizing to taste.{' '}
</AccordionBody>
</AccordionItem>
<AccordionItem name="accordionSmall">
<AccordionHeader>
{' '}Accordion Item #3{' '}
</AccordionHeader>
<AccordionBody>
<strong>
This is the third item’s accordion body.
</strong>
{' '}Combine{' '}
<code>
size="sm"
</code>
{' '}with other props like{' '}
<code>
flush
</code>
{' '}as needed.{' '}
</AccordionBody>
</AccordionItem>
</Accordion>

Flush

Set the flush prop on Accordion to remove some borders and rounded corners so it can sit edge-to-edge with its parent container.

Accordion Item #1
Placeholder content for this accordion, which is intended to demonstrate the flush class. This is the first item’s accordion body.
Accordion Item #2
Placeholder content for this accordion, which is intended to demonstrate the flush class. This is the second item’s accordion body. Let’s imagine this being filled with some actual content.
Accordion Item #3
Placeholder content for this accordion, which is intended to demonstrate the flush class. This is the third item’s accordion body. Nothing more exciting happening here in terms of content, but just filling up the space to make it look, at least at first glance, a bit more representative of how this would look in a real-world application.
<div className="bg-1">
<Accordion flush>
<AccordionItem name="accordionFlushExample">
<AccordionHeader>
{' '}Accordion Item #1{' '}
</AccordionHeader>
<AccordionBody>
Placeholder content for this accordion, which is intended to demonstrate the{' '}
<code>
flush
</code>
{' '}class. This is the first item’s accordion body.
</AccordionBody>
</AccordionItem>
<AccordionItem name="accordionFlushExample">
<AccordionHeader>
{' '}Accordion Item #2{' '}
</AccordionHeader>
<AccordionBody>
Placeholder content for this accordion, which is intended to demonstrate the{' '}
<code>
flush
</code>
{' '}class. This is the second item’s accordion body. Let’s imagine this being filled with some actual content.
</AccordionBody>
</AccordionItem>
<AccordionItem name="accordionFlushExample">
<AccordionHeader>
{' '}Accordion Item #3{' '}
</AccordionHeader>
<AccordionBody>
Placeholder content for this accordion, which is intended to demonstrate the{' '}
<code>
flush
</code>
{' '}class. This is the third item’s accordion body. Nothing more exciting happening here in terms of content, but just filling up the space to make it look, at least at first glance, a bit more representative of how this would look in a real-world application.
</AccordionBody>
</AccordionItem>
</Accordion>
</div>

Gap

Set the gap prop on Accordion to add space between items. Each item is a separate rounded card.

The gap lives on the accordion, not the panel. The panel still animates only its block-size, so the open and close transition stays smooth.

Accordion Item #1
This is the first item’s accordion body. The gap class spaces items apart. Each item keeps a full border radius while the panel opens and closes.
Accordion Item #2
This is the second item’s accordion body. The gap does not change during the transition, so adjacent items do not jump.
Accordion Item #3
This is the third item’s accordion body. Override --accordion-gap to change the space between items.
<Accordion gap>
<AccordionItem
name="accordionGapExample"
open
>
<AccordionHeader>
{' '}Accordion Item #1{' '}
</AccordionHeader>
<AccordionBody>
<strong>
This is the first item’s accordion body.
</strong>
{' '}The{' '}
<code>
gap
</code>
{' '}class spaces items apart. Each item keeps a full border radius while the panel opens and closes.{' '}
</AccordionBody>
</AccordionItem>
<AccordionItem name="accordionGapExample">
<AccordionHeader>
{' '}Accordion Item #2{' '}
</AccordionHeader>
<AccordionBody>
<strong>
This is the second item’s accordion body.
</strong>
{' '}The gap does not change during the transition, so adjacent items do not jump.{' '}
</AccordionBody>
</AccordionItem>
<AccordionItem name="accordionGapExample">
<AccordionHeader>
{' '}Accordion Item #3{' '}
</AccordionHeader>
<AccordionBody>
<strong>
This is the third item’s accordion body.
</strong>
{' '}Override{' '}
<code>
--accordion-gap
</code>
{' '}to change the space between items.{' '}
</AccordionBody>
</AccordionItem>
</Accordion>

Always open

Omit the name attribute on each <details> element to allow multiple accordion items to be open simultaneously.

Accordion Item #1
This is the first item’s accordion body. Without the name attribute, each accordion item operates independently. You can open multiple items at the same time.
Accordion Item #2
This is the second item’s accordion body. Opening this won’t close the first item because there’s no name attribute linking them together.
Accordion Item #3
This is the third item’s accordion body. Each item is completely independent—open or close them in any combination you like.
<Accordion>
<AccordionItem open>
<AccordionHeader>
{' '}Accordion Item #1{' '}
</AccordionHeader>
<AccordionBody>
<strong>
This is the first item’s accordion body.
</strong>
{' '}Without the{' '}
<code>
name
</code>
{' '}attribute, each accordion item operates independently. You can open multiple items at the same time.{' '}
</AccordionBody>
</AccordionItem>
<AccordionItem>
<AccordionHeader>
{' '}Accordion Item #2{' '}
</AccordionHeader>
<AccordionBody>
<strong>
This is the second item’s accordion body.
</strong>
{' '}Opening this won’t close the first item because there’s no{' '}
<code>
name
</code>
{' '}attribute linking them together.{' '}
</AccordionBody>
</AccordionItem>
<AccordionItem>
<AccordionHeader>
{' '}Accordion Item #3{' '}
</AccordionHeader>
<AccordionBody>
<strong>
This is the third item’s accordion body.
</strong>
{' '}Each item is completely independent—open or close them in any combination you like.{' '}
</AccordionBody>
</AccordionItem>
</Accordion>

Expand & Collapse all

To enable expanding and collapsing of all accordion items at once, remove the name attribute from each <details> element using JavaScript. This allows multiple accordion items to be open simultaneously. Restore the name attribute when you collapse the items again if you want exclusive behavior back.

Accordion Item #1
This is the first item’s accordion body. Use Expand all to open every item, even when they share a name.
Accordion Item #2
This is the second item’s accordion body. Collapse all closes every item and restores exclusive name grouping.
Accordion Item #3
This is the third item’s accordion body. If your accordion has no name, you only need to set open on each item.
<>
<AccordionToggle
aria-expanded="false"
className="mb-3"
size="sm"
target="#accordionToggleAll"
theme="secondary"
type="button"
variant="subtle"
>
Expand all
</AccordionToggle>
<Accordion
id="accordionExpandCollapse"
size="sm"
>
<AccordionItem
name="accordionExpandCollapse"
open
>
<AccordionHeader>
{' '}Accordion Item #1{' '}
</AccordionHeader>
<AccordionBody>
<strong>
This is the first item’s accordion body.
</strong>
{' '}Use Expand all to open every item, even when they share a{' '}
<code>
name
</code>
.{' '}
</AccordionBody>
</AccordionItem>
<AccordionItem name="accordionExpandCollapse">
<AccordionHeader>
{' '}Accordion Item #2{' '}
</AccordionHeader>
<AccordionBody>
<strong>
This is the second item’s accordion body.
</strong>
{' '}Collapse all closes every item and restores exclusive{' '}
<code>
name
</code>
{' '}grouping.{' '}
</AccordionBody>
</AccordionItem>
<AccordionItem name="accordionExpandCollapse">
<AccordionHeader>
{' '}Accordion Item #3{' '}
</AccordionHeader>
<AccordionBody>
<strong>
This is the third item’s accordion body.
</strong>
{' '}If your accordion has no{' '}
<code>
name
</code>
, you only need to set{' '}
<code>
open
</code>
{' '}on each item.{' '}
</AccordionBody>
</AccordionItem>
</Accordion>
</>

We use the following JavaScript for this demo:

AccordionToggle handles the expand/collapse-all action and maintains aria-expanded for you.

Nested

Nest an Accordion inside an AccordionBody to create an accordion within an item. Use unique name attribute values for each level so parent and child accordions operate independently.

Accordion Item #1
This is the first item’s accordion body. It contains a nested accordion below.
Nested Item #1
This is the body of the first nested accordion item.
Nested Item #2
This is the body of the second nested accordion item.
Nested Item #3
This is the body of the third nested accordion item.
Accordion Item #2
This is the second item’s accordion body. It does not contain a nested accordion.
Accordion Item #3
This is the third item’s accordion body. It does not contain a nested accordion.
<Accordion>
<AccordionItem
name="accordionNested"
open
>
<AccordionHeader>
{' '}Accordion Item #1{' '}
</AccordionHeader>
<AccordionBody>
<strong>
This is the first item’s accordion body.
</strong>
{' '}It contains a nested accordion below.{' '}
<Accordion className="mt-3">
<AccordionItem
name="accordionNestedInner"
open
>
<AccordionHeader>
{' '}Nested Item #1{' '}
</AccordionHeader>
<AccordionBody>
{' '}This is the body of the first nested accordion item.{' '}
</AccordionBody>
</AccordionItem>
<AccordionItem name="accordionNestedInner">
<AccordionHeader>
{' '}Nested Item #2{' '}
</AccordionHeader>
<AccordionBody>
{' '}This is the body of the second nested accordion item.{' '}
</AccordionBody>
</AccordionItem>
<AccordionItem name="accordionNestedInner">
<AccordionHeader>
{' '}Nested Item #3{' '}
</AccordionHeader>
<AccordionBody>
{' '}This is the body of the third nested accordion item.{' '}
</AccordionBody>
</AccordionItem>
</Accordion>
</AccordionBody>
</AccordionItem>
<AccordionItem name="accordionNested">
<AccordionHeader>
{' '}Accordion Item #2{' '}
</AccordionHeader>
<AccordionBody>
<strong>
This is the second item’s accordion body.
</strong>
{' '}It does not contain a nested accordion.{' '}
</AccordionBody>
</AccordionItem>
<AccordionItem name="accordionNested">
<AccordionHeader>
{' '}Accordion Item #3{' '}
</AccordionHeader>
<AccordionBody>
<strong>
This is the third item’s accordion body.
</strong>
{' '}It does not contain a nested accordion.{' '}
</AccordionBody>
</AccordionItem>
</Accordion>

Accessibility

The native <details> and <summary> elements provide built-in accessibility:

  • Screen readers announce the expanded/collapsed state automatically
  • Keyboard navigation works out of the box (Enter/Space to toggle)
  • The <summary> element is focusable by default
  • No ARIA attributes are required as the semantics are built into the elements

CSS

Variables

Use CSS custom properties on the component to customize its appearance without recompiling Bootstrap.

.accordion {
--bs-accordion-padding-x: 1.25rem;
--bs-accordion-padding-y: 1rem;
--bs-accordion-color: var(--bs-fg-body);
--bs-accordion-bg: var(--bs-bg-body);
--bs-accordion-transition-property: 'color, background-color, border-radius';
--bs-accordion-transition-duration: 0.15s;
--bs-accordion-transition-timing: ease-in-out;
--bs-accordion-panel-transition-property: 'content-visibility, block-size';
--bs-accordion-panel-transition-duration: 0.2s;
--bs-accordion-panel-transition-timing: ease;
--bs-accordion-border-color: var(--bs-border-color);
--bs-accordion-border-width: var(--bs-border-width);
--bs-accordion-border-radius: var(--bs-accordion-radius, var(--bs-radius-7));
--bs-accordion-gap: 0;
--bs-accordion-btn-color: var(--bs-fg-2);
--bs-accordion-btn-bg: var(--bs-bg-body);
--bs-accordion-btn-icon-width: 1rem;
--bs-accordion-btn-icon-transform: rotate(-180deg);
--bs-accordion-btn-icon-transition: transform 0.2s ease-in-out;
--bs-accordion-active-color: var(--bs-fg-body);
--bs-accordion-active-bg: var(--bs-bg-2);
}

Customize

Custom icons

Use the icon prop on AccordionHeader to choose an Icon font name, or icon={false} to remove it.

<AccordionHeader icon="plus-lg">Accordion title</AccordionHeader>

Events

Use the native onToggle prop on AccordionItem to respond to open-state changes.

Programmatic control

Pass the native open prop to AccordionItem to control its state. AccordionToggle target="#id" expands or collapses all items together.

Documentation navigation
On this page
On this page