Bootstrap Collapse

Learn how to collapse content using the Bootstrap collapse class. With that, learn how to:

  • Display content always
  • Create Accordion

To set content as collapsable content, use the .collapse class and the data-bs-toggle=”collapse” attribute.

To display content always, use the:

  • .show class

To create an Accordion, use the:

  • data-parent attribute

Example – Bootstrap Collapse

Let us now see an example to create Collapse in Bootstrap:

<!DOCTYPE html>
<html lang="en">
   <head>
      <title>Bootstrap Collapsible Example</title>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
   </head>
   <body>
      <div class="container">
         <p>Demo</p>
         <button type="button" class="btn btn-danger" data-bs-toggle="collapse" data-bs-target="#test">More Details</button>
         <div id="test" class="collapse">
            Tickets will be sold from 9AM TO 5PM. Tickets will be sold from 9AM TO
            5PM.
            Tickets will be sold from 9AM TO 5PM. Tickets will be sold from 9AM TO
            5PM.
         </div>
      </div>
   </body>
</html>

Output

Bootstrap Collapse Example

Click the More Details button:

Bootstrap Collapse Example

Video Tutorial – Bootstrap Collapse

The following is the complete video tutorial to learn how to work with Collapse in Bootstrap:


If you liked the tutorial, spread the word and share the link and our website Studyopedia with others.


Read More:

Bootstrap Cards
Bootstrap Dropdown
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment