Bootstrap 4 Collapse


Basic Collapse

To show or hide a large amount of data in bootstrap with a button, you need to add .collapse class.

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed tempor and vitality, so that the labor and sorrow, some important things to do eiusmod. Over the years, I will come, who will nostrud aliquip out of her the advantage of exercise, so that stimulus efforts if the school district and longevity.

Example code

<button class="btn-primary btn" data-toggle="collapse" data-target="#Example">Show/Hide</button>
<div class="collapse" id="Example">
Lorem ipsum dolor sit amet.....
</div>

Collapse With Button

To show or hide a large amount of data in bootstrap with a button, you need to add .collapse class. Follow the steps below-

  1. First you need to create a button. In that button, two attributes have to be create data-toggle = "collapse" and data-target = "#demo" (the id of the collapsible div must be given).
  2. Then create a div and add .collapse to its class, create id = "demo" (this id must be used on button's data-target) attribute. And you can give the content you want inside it.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed tempor and vitality, so that the labor and sorrow, some important things to do eiusmod. Over the years, I will come, who will nostrud aliquip out of her the advantage of exercise, so that stimulus efforts if the school district and longevity.

Example code

<button class="btn-primary btn" data-toggle="collapse" data-target="#demo">Show/Hide</button>
<div class="collapse" id="demo">
Lorem ipsum dolor sit amet.....
</div>

Collapse With Link

To show or hide a large amount of data in bootstrap with a link, you need to add .collapse class. Follow the steps below-

  1. First you need to create a link. In that link, two attributes have to be create data-toggle = "collapse" and href = "#demo1" (the id of the collapsible div must be given).
  2. Then create a div and add .collapse to its class, create id = "demo1" (this id must be used on link's href) attribute. And you can give the content you want inside it.
Show/Hide
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed tempor and vitality, so that the labor and sorrow, some important things to do eiusmod. Over the years, I will come, who will nostrud aliquip out of her the advantage of exercise, so that stimulus efforts if the school district and longevity.

Example code

<a href="#demo1" class="btn-primary btn" data-toggle="collapse">Show/Hide</a>
<div class="collapse" id="demo1">
Lorem ipsum dolor sit amet....
</div>

Show Collapse

By default, the contents of the collapse class are hidden but if you want to show it by default then you have to add the .show class with the .collapse class.

Show/Hide
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed tempor and vitality, so that the labor and sorrow, some important things to do eiusmod. Over the years, I will come, who will nostrud aliquip out of her the advantage of exercise, so that stimulus efforts if the school district and longevity.

Example code

<a href="#demo2" class="btn-primary btn" data-toggle="collapse">Show/Hide</a>
<div class="collapse show" id="demo2">
Lorem ipsum dolor sit amet....
</div>

Accordian using Collapse

An accordion is created with more than one collapse content through an example. All collapse content to stay inside the accordion.

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed tempor and vitality, so that the labor and sorrow, some important things to do eiusmod. Over the years, I will come, who will nostrud aliquip out of her the advantage of exercise, so that stimulus efforts if the school district and longevity.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed tempor and vitality, so that the labor and sorrow, some important things to do eiusmod. Over the years, I will come, who will nostrud aliquip out of her the advantage of exercise, so that stimulus efforts if the school district and longevity.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed tempor and vitality, so that the labor and sorrow, some important things to do eiusmod. Over the years, I will come, who will nostrud aliquip out of her the advantage of exercise, so that stimulus efforts if the school district and longevity.

Example code

<div id="accordion">
    <div class="card">
      <div class="card-header">
        <a class="card-link" data-toggle="collapse" href="#FirstItemData">
          First Item
        </a>
      </div>
      <div id="FirstItemData" class="collapse show" data-parent="#accordion">
        <div class="card-body">
          Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed tempor and vitality, so that the labor and sorrow, some important things to do eiusmod. Over the years, I will come, who will nostrud aliquip out of her the advantage of exercise, so that stimulus efforts if the school district and longevity.
        </div>
      </div>
    </div>
    <div class="card">
      <div class="card-header">
        <a class="collapsed card-link" data-toggle="collapse" href="#SecondItemData">
        Second Item
      </a>
      </div>
      <div id="SecondItemData" class="collapse" data-parent="#accordion">
        <div class="card-body">
          Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed tempor and vitality, so that the labor and sorrow, some important things to do eiusmod. Over the years, I will come, who will nostrud aliquip out of her the advantage of exercise, so that stimulus efforts if the school district and longevity.
        </div>
      </div>
    </div>
    <div class="card">
      <div class="card-header">
        <a class="collapsed card-link" data-toggle="collapse" href="#ThirdItemData">
          Third Item
        </a>
      </div>
      <div id="ThirdItemData" class="collapse" data-parent="#accordion">
        <div class="card-body">
          Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed tempor and vitality, so that the labor and sorrow, some important things to do eiusmod. Over the years, I will come, who will nostrud aliquip out of her the advantage of exercise, so that stimulus efforts if the school district and longevity.
        </div>
      </div>
    </div>
 </div>