Toggle the visibility of content across your project with a few classes and our JavaScript plugins.
Read the official Bootstrap Documentation for a full list of instructions and other options.
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.
<p class="demo-inline-spacing">
<a class="btn btn-primary me-1" data-bs-toggle="collapse" href="#collapseExample" role="button" aria-expanded="false" aria-controls="collapseExample">
Link with href
</a>
<button class="btn btn-primary me-1" type="button" data-bs-toggle="collapse" data-bs-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
Button with data-bs-target
</button>
</p>
<div class="collapse" id="collapseExample">
<div class="d-flex p-4 border">
<img src="../../assets/img/elements/1.png" alt="collapse-image" height="125" class="me-4 mb-sm-0 mb-2">
<span>
...
</span>
</div>
</div>
The collapse plugin also supports horizontal collapsing. To achieve this, add the
.collapse-horizontal
modifier class, which transitions the width instead of the height. Additionally, ensure you set a width on the immediate child element. You can accomplish this by writing custom Sass, applying inline styles, or using our built-in width utilities.
If you want the collapse to be closed by default, simply remove the .show
class from the .collapse-horizontal
class.
min-height
is set to prevent excessive repaints within our documentation. However, this is not a mandatory requirement;
Only the width
on the child element is required.
<p class="demo-inline-spacing">
<button
class="btn btn-primary"
type="button"
data-bs-toggle="collapse"
data-bs-target="#collapseWidthExample"
aria-expanded="false"
aria-controls="collapseWidthExample">
Toggle width collapse
</button>
</p>
<div style="min-height: 97px;">
<div class="collapse-horizontal collapse show" id="collapseWidthExample">
<div class="p-4 border rounded" style="width: 300px;">
Lorem Ipsum is simply dummy text of the printing and typesetting industry Ipsum has been the.
</div>
</div>
</div>
A <button>
or <a>
element can show and hide multiple elements by referencing them with a selector in its data-bs-target
or href
attribute. Conversely, multiple <button>
or <a>
elements can show and hide the same element if they each reference it with their data-bs-target
or href
attribute.
<p class="demo-inline-spacing">
<a class="btn btn-primary me-1" data-bs-toggle="collapse" href="#multiCollapseExample1" role="button" aria-expanded="false" aria-controls="multiCollapseExample1">Toggle first element</a>
<button class="btn btn-primary me-1" type="button" data-bs-toggle="collapse" data-bs-target="#multiCollapseExample2" aria-expanded="false" aria-controls="multiCollapseExample2">
Toggle second element
</button>
<button class="btn btn-primary me-1" type="button" data-bs-toggle="collapse" data-bs-target=".multi-collapse" aria-expanded="false" aria-controls="multiCollapseExample1 multiCollapseExample2">
Toggle both elements
</button>
</p>
<div class="row">
<div class="col-12 col-md-6 mb-4 mb-md-0">
<div class="collapse multi-collapse" id="multiCollapseExample1">
<div class="d-flex p-4 border">
<img src="../../assets/img/elements/2.png" alt="collapse-image" height="125" class="me-4 mb-sm-0 mb-2">
<span>
...
</span>
</div>
</div>
</div>
<div class="col-12 col-md-6">
<div class="collapse multi-collapse" id="multiCollapseExample2">
<div class="d-flex p-4 border">
<img src="../../assets/img/elements/3.png" alt="collapse-image" height="125" class="me-4 mb-sm-0 mb-2">
<span>
...
</span>
</div>
</div>
</div>
</div>