Bootstrap 4 collapse feature is used to show and hide large amount of information.
<a>
or <button>
to link collapsible element.
data-toggle="collapse"
to either <a>
or <button>
and other data attribute data-target="#id-of-collpasible-element"
to only <button>
while as href="#"
is used by <a>
to link collasible element.
id="id-of-collapse-element"
and .collapse
to the collapsible element .
General Syntax
<button data-toggle="collapse" data-target="#demo_id">Show Collapsible Features</button>
<div id="demo_id" class="collapse">
Write Your Content
</div>
Source Code
<div class="container text-center mt-4">
<h2 class="text-center">Bootstrap Collapse</h2>
<button data-toggle="collapse" data-target="#myBlockId" class="btn btn-success">Learn Bootstrap</button>
<div id="myBlockId" class="collapse mt-5">
Bootstrap is an HTML,CSS & Javascript based CSS framework that is widely used during web development.
</div>
</div>
Source Code: Output
Note: Bootstrap collapse feature is used to show and hide the text information.
By default, collapsible element is hidden. To show the hidden content, you have to use .show
to collapsible elements(<div>
containing class.collapse
).
Source Code
<div class="container text-center mt-4">
<h2 class="text-center">Bootstrap Collapse</h2>
<button data-toggle="collapse" data-target="#myBlockId" class="btn btn-success">Click To Show The Effect</button>
<div id="myBlockId" class="collapse show mt-5">
Bootstrap is an HTML, CSS & Javascript-based CSS framework that is widely used during web development.
</div>
</div>
Source Code: Output
Note: In the above example,.show
is applied to show the collapsible element content.