Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

Bootstrap 4 JS Collapse


Collapse CSS Classes

For a tutorial about Collapsibles, read our Bootstrap Collapse Tutorial.

Class Description Example
.collapse Hides the content Try it
.collapse show Shows the collapsible content by default Try it
.collapsing Added when the transition starts, and removed when it finishes Try it

Via data-* Attributes

Just add data-toggle="collapse" and a data-target to element to automatically assign control of a collapsible element. The data-target attribute accepts a CSS selector to apply the collapse to. Be sure to add the class collapse to the collapsible element. If you'd like it to default open, add the additional class "show".

Example

<button class="btn" data-toggle="collapse" data-target="#demo">Collapsible</button>

<div id="demo" class="collapse">
Some text..
</div>
Try it Yourself »

Tip: To add accordion-like group management to a collapsible control, add the data attribute data-parent="#selector".


Via JavaScript

Enable manually with:

$('.collapse').collapse()

Collapse Options

Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-, as in data-parent="".

Name Type Default Description Try it
parent selector false All collapsible elements under the specified parent will be closed when this collapsible item is shown. (similar to traditional accordion behavior) Try it
toggle boolean true Toggles the collapsible element on invocation Try it

Collapse Methods

The following table lists all available collapse methods.

Method Description Try it
.collapse(options) Activates the collapsible element with an option. See options above for valid values
.collapse("toggle") Toggles the collapsible element Try it
.collapse("show") Shows the collapsible element Try it
.collapse("hide") Hides the collapsible element Try it
.collapse("dispose") Destroys the collapsible element

Collapse Events

The following table lists all available collapse events.

Event Description Try it
show.bs.collapse Occurs when the collapsible element is about to be shown Try it
shown.bs.collapse Occurs when the collapsible element is fully shown (after CSS transitions have completed) Try it
hide.bs.collapse Occurs when the collapsible element is about to be hidden Try it
hidden.bs.collapse Occurs when the collapsible element is fully hidden (after CSS transitions have completed) Try it

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.