Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Bootstrap5 Collapse

Bootstrap5 Collapse

Bootstrap5 Collapse can easily show and hide content.

data-bs-toggle and data-bs-target are custom data attributes used to define component behavior and target elements.

1. data-bs-toggle attribute:

2. data-bs-target attribute:

In the following example, when the button is clicked, the data-bs-toggle="collapse" attribute triggers the collapse menu behavior, and the data-bs-target="#demo" attribute specifies that the target element of the collapse menu is the

.

Example

<button data-bs-toggle="collapse" data-bs-target="#demo" Collapse button>
<div id="demo" class="collapse">

Here is some test content...

div

Try it »

Example Parsing

The .collapse class is used to specify a collapsible element (the

in the example); clicking the button toggles between hidden and shown.

To control the hiding and showing of content, you need to add the or