Accordion

Source: https://getbootstrap.com/docs/6.0/components/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.

<details class="accordion-item" name="accordionExample" open> <summary class="accordion-header"> Accordion Item #1 <svg class="accordion-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"><path d="m2 5 6 6 6-6"/></svg> </summary> <div class="accordion-body"> <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>. </div> </details> <details class="accordion-item" name="accordionExample"> <summary class="accordion-header"> Accordion Item #2 <svg class="accordion-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"><path d="m2 5 6 6 6-6"/></svg> </summary> <div class="accordion-body"> <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. </div> </details> <details class="accordion-item" name="accordionExample"> <summary class="accordion-header"> Accordion Item #3 <svg class="accordion-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"><path d="m2 5 6 6 6-6"/></svg> </summary> <div class="accordion-body"> <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. </div> </details> </div>`} />

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.

Variants

Use the contextual .theme-{color} classes to apply a semantic theme color to open accordion items.

<details class="accordion-item" name="accordionExampleTheme" open> <summary class="accordion-header"> Accordion Item #1 <svg class="accordion-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"><path d="m2 5 6 6 6-6"/></svg> </summary> <div class="accordion-body"> <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>. </div> </details> <details class="accordion-item" name="accordionExampleTheme"> <summary class="accordion-header"> Accordion Item #2 <svg class="accordion-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"><path d="m2 5 6 6 6-6"/></svg> </summary> <div class="accordion-body"> <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. </div> </details> <details class="accordion-item" name="accordionExampleTheme"> <summary class="accordion-header"> Accordion Item #3 <svg class="accordion-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"><path d="m2 5 6 6 6-6"/></svg> </summary> <div class="accordion-body"> <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. </div> </details> </div>} customMarkup={<div class="accordion theme-primary"><!--[!code highlight]--> <!-- Accordion items here --> </div>`} />

Small

Add .accordion-sm to the .accordion for a more compact accordion with tighter padding, a smaller border radius, and a smaller font size.

<details class="accordion-item" name="accordionSmall" open> <summary class="accordion-header"> Accordion Item #1 <svg class="accordion-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"><path d="m2 5 6 6 6-6"/></svg> </summary> <div class="accordion-body"> <strong>This is the first item’s accordion body.</strong> The <code>.accordion-sm</code> class tightens up the padding, border radius, and font size for a more compact presentation. </div> </details> <details class="accordion-item" name="accordionSmall"> <summary class="accordion-header"> Accordion Item #2 <svg class="accordion-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"><path d="m2 5 6 6 6-6"/></svg> </summary> <div class="accordion-body"> <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. </div> </details> <details class="accordion-item" name="accordionSmall"> <summary class="accordion-header"> Accordion Item #3 <svg class="accordion-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"><path d="m2 5 6 6 6-6"/></svg> </summary> <div class="accordion-body"> <strong>This is the third item’s accordion body.</strong> Combine <code>.accordion-sm</code> with other variants like <code>.accordion-flush</code> as needed. </div> </details> </div>} customMarkup={<div class="accordion accordion-sm"><!--[!code highlight]--> <!-- Accordion items here --> </div>`} />

Flush

Add .accordion-flush to remove some borders and rounded corners to render accordions edge-to-edge with their parent container.

<details class="accordion-item" name="accordionFlushExample"> <summary class="accordion-header"> Accordion Item #1 <svg class="accordion-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"><path d="m2 5 6 6 6-6"/></svg> </summary> <div class="accordion-body">Placeholder content for this accordion, which is intended to demonstrate the <code>.accordion-flush</code> class. This is the first item’s accordion body.</div> </details> <details class="accordion-item" name="accordionFlushExample"> <summary class="accordion-header"> Accordion Item #2 <svg class="accordion-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"><path d="m2 5 6 6 6-6"/></svg> </summary> <div class="accordion-body">Placeholder content for this accordion, which is intended to demonstrate the <code>.accordion-flush</code> class. This is the second item’s accordion body. Let’s imagine this being filled with some actual content.</div> </details> <details class="accordion-item" name="accordionFlushExample"> <summary class="accordion-header"> Accordion Item #3 <svg class="accordion-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"><path d="m2 5 6 6 6-6"/></svg> </summary> <div class="accordion-body">Placeholder content for this accordion, which is intended to demonstrate the <code>.accordion-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.</div> </details> </div>} customMarkup={<div class="accordion accordion-flush"><!--[!code highlight]--> <!-- Accordion items here --> </div>`} />

Gap

Add .accordion-gap to put space between accordion 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.

<details class="accordion-item" name="accordionGapExample" open> <summary class="accordion-header"> Accordion Item #1 <svg class="accordion-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"><path d="m2 5 6 6 6-6"/></svg> </summary> <div class="accordion-body"> <strong>This is the first item’s accordion body.</strong> The <code>.accordion-gap</code> class spaces items apart. Each item keeps a full border radius while the panel opens and closes. </div> </details> <details class="accordion-item" name="accordionGapExample"> <summary class="accordion-header"> Accordion Item #2 <svg class="accordion-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"><path d="m2 5 6 6 6-6"/></svg> </summary> <div class="accordion-body"> <strong>This is the second item’s accordion body.</strong> The gap does not change during the transition, so adjacent items do not jump. </div> </details> <details class="accordion-item" name="accordionGapExample"> <summary class="accordion-header"> Accordion Item #3 <svg class="accordion-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"><path d="m2 5 6 6 6-6"/></svg> </summary> <div class="accordion-body"> <strong>This is the third item’s accordion body.</strong> Override <code>--accordion-gap</code> to change the space between items. </div> </details> </div>} customMarkup={<div class="accordion accordion-gap"><!--[!code highlight]--> <!-- Accordion items here --> </div>`} />