Accordion & Collapse

Bootstrap Framework 9 min min read Updated: Nov 16, 2026 Beginner
Accordion & Collapse
Beginner Topic 10 of 14

Collapse: Show and Hide Content

Collapse lets a button show or hide a block of content, with a smooth animation.

html <button class="btn btn-primary" data-bs-toggle="collapse" data-bs-target="#more"> Show details </button> <div class="collapse mt-3" id="more"> <div class="card card-body"> This content appears when you click the button. </div> </div>
  • collapse hides the content at the start
  • data-bs-target points to the id of the content
  • Add show to the class if the content should be open at the start

Accordion

An accordion is a group of collapse items where opening one closes the others, which is perfect for FAQ pages.

html <div class="accordion" id="faq"> <div class="accordion-item"> <h2 class="accordion-header"> <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#q1"> What is Bootstrap? </button> </h2> <div id="q1" class="accordion-collapse collapse show" data-bs-parent="#faq"> <div class="accordion-body"> Bootstrap is a CSS framework for building responsive websites. </div> </div> </div> <div class="accordion-item"> <h2 class="accordion-header"> <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#q2"> Is Bootstrap free? </button> </h2> <div id="q2" class="accordion-collapse collapse" data-bs-parent="#faq"> <div class="accordion-body"> Yes, Bootstrap is free and open source. </div> </div> </div> </div>
Result

Two questions. Opening one answer automatically closes the other.

The Important Attributes

Attribute or ClassMeaning
data-bs-parent="#faq"Makes the accordion close other items when one opens
collapsed on the buttonShows the closed arrow icon
show on the panelOpens it at page load
accordion-flushRemoves borders and rounded corners for a clean look

Always Open

Remove the data-bs-parent attribute and each item will open and close independently.

SEO and UX tip: Accordions are excellent for FAQs. Keep questions clear and answers short.

Conclusion

Collapse and accordion save space and keep long pages tidy. Always make sure each button target matches the right id.

Quick Summary: collapse toggles one block. accordion groups collapse items and data-bs-parent keeps only one open.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators