Collapse
Toggle the visibility of content across your project with a few classes and our JavaScript plugins..
The collapse JavaScript plugin is used to show and hide content. Buttons or anchors are used as triggers that are mapped to specific elements you toggle. Collapsing an element will animate the height from its current value to 0. Given how CSS handles animations, you cannot use padding on a .collapse element. Instead, use the class as an independent wrapping element.
Button Collapse
You can use a link with the href attribute, or a button with the data-target attribute. In both cases, the data-toggle="collapse" is required.
<p>
<a class="btn btn-brand" data-toggle="collapse" href="#collapseExample" role="button" aria-expanded="false" aria-controls="collapseExample">
Link with href
</a>
<button class="btn btn-brand-muted" type="button" data-toggle="collapse" data-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
Button with data-target
</button>
</p>
<div class="collapse" id="collapseExample">
<div class="card card-body font-sm">
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident.
</div>
</div>
Accordions
Using the card component, you can extend the default collapse behavior to create an accordion. To properly achieve the accordion style, be sure to use .accordion as a wrapper.
<div class="accordion accordion-toggle-arrow" id="accordionExample1">
<div class="card">
<div class="card-header">
<div class="card-title" data-toggle="collapse" data-target="#collapseOne1">
Collapsible Group Item #1
</div>
</div>
<div id="collapseOne1" class="collapse show" data-parent="#accordionExample1">
<div class="card-body">
Anim pariatur cliche reprehenderit...
</div>
</div>
</div>
</div>
Multiple targets
A <button> or <a> can show and hide multiple elements by referencing them with a JQuery selector in its href or data-target attribute.
Multiple <button> or <a> can show and hide an element if they each reference it with their href or data-target attribute
<p>
<a class="btn btn-brand btn-sm" data-toggle="collapse" href="#multiCollapse1" role="button" aria-expanded="false" aria-controls="multiCollapse1">Toggle 1</a>
<button class="btn btn-primary btn-sm" type="button" data-toggle="collapse" data-target="#multiCollapse2" aria-expanded="false" aria-controls="multiCollapse2">Toggle 2</button>
<button class="btn btn-success btn-sm" type="button" data-toggle="collapse" data-target=".multi-collapse-example" aria-expanded="false" aria-controls="multiCollapse1 multiCollapse2">Toggle both</button>
</p>
<div class="row">
<div class="col">
<div class="collapse multi-collapse-example" id="multiCollapse1">
<div class="card card-body bg-brand-muted font-sm">
Anim pariatur cliche...
</div>
</div>
</div>
<div class="col">
<div class="collapse multi-collapse-example" id="multiCollapse2">
<div class="card card-body bg-primary-muted font-sm">
Anim pariatur...
</div>
</div>
</div>
</div>
Light Accordions
Using the .accordion-light .
<div class="accordion accordion-light accordion-toggle-arrow" id="accordionExample1">
<div class="card">
<div class="card-header">
<div class="card-title" data-toggle="collapse" data-target="#collapseOne1">
Collapsible Group Item #1
</div>
</div>
<div id="collapseOne1" class="collapse show" data-parent="#accordionExample1">
<div class="card-body">
Anim pariatur cliche reprehenderit...
</div>
</div>
</div>
</div>
Accessibility
Be sure to add aria-expanded to the control element. This attribute explicitly conveys the current state of the collapsible element tied to the control to screen readers and similar assistive technologies. If the collapsible element is closed by default, the attribute on the control element should have a value of aria-expanded="false". If you???ve set the collapsible element to be open by default using the show class, set aria-expanded="true" on the control instead. The plugin will automatically toggle this attribute on the control based on whether or not the collapsible element has been opened or closed (via JavaScript, or because the user triggered another control element also tied to the same collapsible element). If the control element???s HTML element is not a button (e.g., an <a> or <div>), the attribute role="button" should be added to the element.
If your control element is targeting a single collapsible element ??? i.e. the data-target attribute is pointing to an id selector ??? you should add the aria-controls attribute to the control element, containing the id of the collapsible element. Modern screen readers and similar assistive technologies make use of this attribute to provide users with additional shortcuts to navigate directly to the collapsible element itself.
Note that Bootstrap???s current implementation does not cover the various keyboard interactions described in the WAI-ARIA Authoring Practices 1.1 accordion pattern - you will need to include these yourself with custom JavaScript.