Collapsible options
Examples of elements and statesInline or block element
In this example, collapsible JS plugin is attached to inline
<span>
element instead of button or link
Text links
Inline links with href
attribute also can toggle the
visibility of content, where href is an ID of collapsible container
Link with href
While not recommended from a semantic point of view, you can also use a
link with the href
attribute
Button with data attribute
We recommend using a button with the data-bs-target
attribute, use of data-bs-toggle="collapse"
is required
Input with data attribute
You can also use collapsible attached to
input type="button"
, although this tag is generally not recommended
Open by default
Collapsible content can be expanded by default. Use .show
in .collapse
element to expand content
Collapsible width
Add the .collapse-horizontal
modifier class to
.collapse
and set a width
on the immediate child element
Input with data attribute
A button
or a
can show and hide multiple
elements by referencing them with a selector in its href
or
data-bs-target
attribute
Accordion markup
Collapsible content sections can be attached to any markup, in this example it's using markup from our Accordion component. The accordion component has two main states: collapsed and expanded. The chevron icon at the end of the accordion indicates which state the accordion is in. The chevron points down to indicate collapsed and up to indicate expanded.
.accordion-body
, though the transition does limit overflow.
.accordion-body
, though the transition does limit overflow.
.accordion-body
, though the transition does limit overflow.
Cards
Content cards can be collapsible as well, and you can control what toggler
triggers it: all elements in card header, card title text, icon or a specific element.
Be sure to place the toggler outside <div class="collapse">
container.
In the following example card title is a regular anchor element with
.text-body
class that is highlighted with different color in active state.
Card group
Card group is a list of cards that are displayed seamlessly as 1 component.
All cards in this layout require a wrapper container with
.card-group-vertical
class, which cleans up all spacings and borders in
children cards. Height collapse in horizontal card group is also supported. Toggler
options are similar to previous example.
Toggle indicator
You can also add a visual indication of current collapsible state. The icon
is not hardcoded, which means you can use any icon from the default pack, just make sure
you add .collapsible-indicator
class to icon element. This class looks for
.collapsed
class in parent container and rotates the icon depending on the
state. Icon indicator can aligned to the left and right.
Nested elements
All collapsible elements work independently, if ID's in toggle button and collapsible containers match. This allows you to have as many nested collapsible elements as we need. In this example we have a set of collapsible cards, each of them has another set of collapsible elements. All options from the examples above are fully supported.
Here goes some text content and a set of collapsible elements in the card #1
Here goes some text content and a set of collapsible elements in the card #2
Here goes some text content and a set of collapsible elements in the card #3