Accordion

Build vertically collapsing accordions in combination with Bootstrap Collapse JavaScript plugin.

How it works

The accordion uses collapse internally to make it collapsible. To render an accordion that's expanded, add the show prop on the x-accordion.item component.

Basic example

Click the accordions below to expand/collapse the accordion content. As you may notice the id it's not mandatory for x-accordion component since it's generated in component class when missed. In case you set the id that one will be used instead of generated one. The prop item on x-accordion.item component should be unique since will be used for set required id to accordion header and collapse button. In the generated HTML output you will notice the value of prop id used to set id="heading-generated-id" and id="collapse-generated-id". Like for id of x-accordion, the prop id of x-accordion.item it's not mandatory, in case is missing it will be generated in component class. Confused? You don't need. Just remember that you don't need to set any IDs.

This is the first item's accordion body. It is shown by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the .accordion-body, though the transition does limit overflow.

This is the second item's accordion body. It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the .accordion-body, though the transition does limit overflow.

This is the third item's accordion body. It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the .accordion-body, though the transition does limit overflow.
<x-accordion>
  <x-accordion.item title="First accordion" show>
    <!-- Content go here -->
  </x-accordion.item>

  <x-accordion.item title="Second accordion">
    <!-- Content go here -->
  </x-accordion.item>

  <x-accordion.item title="Third accordion">
    <!-- Content go here -->
  </x-accordion.item>
</x-accordion>

<!-- Optionally you can set your custom IDs -->

<x-accordion id="myAccordion">
  <x-accordion.item id="myFirstItem" title="First accordion" show>
    <!-- Content go here -->
  </x-accordion.item>

  <x-accordion.item id="mySecondItem" title="Second accordion">
    <!-- Content go here -->
  </x-accordion.item>

  <x-accordion.item id="myThirdItem" title="Third accordion">
    <!-- Content go here -->
  </x-accordion.item>
</x-accordion>
<div id="accordion-v9W4WVJbHWJnXZDkj6S3"
     class="accordion">
  <div class="accordion-item">
    <h2 class="accordion-header"
        id="heading-LVjaAiO6PxZocF7WwozI">
      <button type="button"
          class="accordion-button"
          data-bs-toggle="collapse"
          data-bs-target="#collapse-LVjaAiO6PxZocF7WwozI"
          aria-expanded="true"
          aria-controls="collapse-LVjaAiO6PxZocF7WwozI">First accordion</button>
    </h2>

    <div data-bs-parent="#accordion-v9W4WVJbHWJnXZDkj6S3"
         id="collapse-LVjaAiO6PxZocF7WwozI"
         aria-labelledby="heading-LVjaAiO6PxZocF7WwozI"
         class="accordion-collapse collapse show">
      <div class="accordion-body">
        <strong>This is the first item's accordion body.</strong> It is shown by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
      </div>
    </div>
  </div>

  <div class="accordion-item">
    <h2 class="accordion-header"
        id="heading-IBvqzWU8lnRZhMNPDhUn">
      <button type="button"
          class="accordion-button collapsed"
          data-bs-toggle="collapse"
          data-bs-target="#collapse-IBvqzWU8lnRZhMNPDhUn"
          aria-expanded="false"
          aria-controls="collapse-IBvqzWU8lnRZhMNPDhUn">Second accordion</button>
    </h2>

    <div data-bs-parent="#accordion-v9W4WVJbHWJnXZDkj6S3"
         id="collapse-IBvqzWU8lnRZhMNPDhUn"
         aria-labelledby="heading-IBvqzWU8lnRZhMNPDhUn"
         class="accordion-collapse collapse">
      <div class="accordion-body">
        <strong>This is the second item's accordion body.</strong> It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
      </div>
    </div>
  </div>

  <div class="accordion-item">
    <h2 class="accordion-header"
        id="heading-PDAeXH4VHDwGPSmxRtm6">
      <button type="button"
          class="accordion-button collapsed"
          data-bs-toggle="collapse"
          data-bs-target="#collapse-PDAeXH4VHDwGPSmxRtm6"
          aria-expanded="false"
          aria-controls="collapse-PDAeXH4VHDwGPSmxRtm6">Third accordion</button>
    </h2>

    <div data-bs-parent="#accordion-v9W4WVJbHWJnXZDkj6S3"
         id="collapse-PDAeXH4VHDwGPSmxRtm6"
         aria-labelledby="heading-PDAeXH4VHDwGPSmxRtm6"
         class="accordion-collapse collapse">
      <div class="accordion-body">
        <strong>This is the third item's accordion body.</strong> It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
      </div>
    </div>
  </div>
</div>

Flush and always open

Add prop flush to remove the default background-color, some borders, and some rounded corners to render accordions edge-to-edge with their parent container. And add prop always-open to make accordion items stay open when another item is opened.

This is the first item's accordion body. It is shown by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the .accordion-body, though the transition does limit overflow.

This is the second item's accordion body. It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the .accordion-body, though the transition does limit overflow.

This is the third item's accordion body. It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the .accordion-body, though the transition does limit overflow.
<x-accordion id="FlushAndAlwaysOpen" flush always-open>
    <!-- Content go here -->
</x-accordion>
<div id="FlushAndAlwaysOpen"
     class="accordion accordion-flush">
  <div class="accordion-item">
    <h2 class="accordion-header"
        id="heading-0t1JjnB5o5m0euiYQ5NT">
      <button type="button"
          class="accordion-button"
          data-bs-toggle="collapse"
          data-bs-target="#collapse-0t1JjnB5o5m0euiYQ5NT"
          aria-expanded="true"
          aria-controls="collapse-0t1JjnB5o5m0euiYQ5NT">First accordion</button>
    </h2>

    <div id="collapse-0t1JjnB5o5m0euiYQ5NT"
         aria-labelledby="heading-0t1JjnB5o5m0euiYQ5NT"
         class="accordion-collapse collapse show"
         item="first2">
      <div class="accordion-body">
        <strong>This is the first item's accordion body.</strong> It is shown by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
      </div>
    </div>
  </div>

  <div class="accordion-item">
    <h2 class="accordion-header"
        id="heading-8I7ZTCjqtUq3OnB9RrvV">
      <button type="button"
          class="accordion-button collapsed"
          data-bs-toggle="collapse"
          data-bs-target="#collapse-8I7ZTCjqtUq3OnB9RrvV"
          aria-expanded="false"
          aria-controls="collapse-8I7ZTCjqtUq3OnB9RrvV">Second accordion</button>
    </h2>

    <div id="collapse-8I7ZTCjqtUq3OnB9RrvV"
         aria-labelledby="heading-8I7ZTCjqtUq3OnB9RrvV"
         class="accordion-collapse collapse"
         item="second2">
      <div class="accordion-body">
        <strong>This is the second item's accordion body.</strong> It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
      </div>
    </div>
  </div>

  <div class="accordion-item">
    <h2 class="accordion-header"
        id="heading-ySVgmVb3Wi7fDz1aDr5q">
      <button type="button"
          class="accordion-button collapsed"
          data-bs-toggle="collapse"
          data-bs-target="#collapse-ySVgmVb3Wi7fDz1aDr5q"
          aria-expanded="false"
          aria-controls="collapse-ySVgmVb3Wi7fDz1aDr5q">Third accordion</button>
    </h2>

    <div id="collapse-ySVgmVb3Wi7fDz1aDr5q"
         aria-labelledby="heading-ySVgmVb3Wi7fDz1aDr5q"
         class="accordion-collapse collapse"
         item="third2">
      <div class="accordion-body">
        <strong>This is the third item's accordion body.</strong> It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
      </div>
    </div>
  </div>
</div>