Accordion
Bootstrap 5 Accordion component
Responsive accordion built with the latest Bootstrap 5. Accordion is a vertically collapsing element to show and hide content via class changes.
Build vertically collapsing accordions in combination with our Collapse JavaScript plugin.
How it works
The accordion uses collapse internally to
make it collapsible. To render an accordion that’s expanded, add the .show
class
on the .accordion-collapse
.
*
*
UMD autoinits are enabled
by default. This means that you don't need to initialize
the component manually. However if you are using MDBootstrap ES format then you should pass
the required components to the initMDB
method.
Basic example
Click the accordions below to expand/collapse the accordion content.
.accordion-body
, though the transition does limit overflow.
.accordion-body
, though the transition does limit overflow.
.accordion-body
, though the transition does limit overflow.
Flush
Add .accordion-flush
to remove the default background-color
, some
borders, and some rounded corners to render accordions edge-to-edge with their parent
container.
Borderless
Add .accordion-borderless
to remove all the borders and add a background color to
the active item.
.accordion-flush
class. This is the first item's accordion body.
.accordion-flush
class. This is the second item's accordion body. Let's
imagine this being filled with some actual content.
.accordion-flush
class. This is the third item's accordion body. Nothing
more exciting happening here in terms of content, but just filling up the space to
make it look, at least at first glance, a bit more representative of how this would
look in a real-world application.
With icons
You can easily add icons to the header of the accordion. Read icons docs to see all the available icons.
.accordion-body
, though the transition does limit overflow.
.accordion-body
, though the transition does limit overflow.
.accordion-body
, though the transition does limit overflow.
Always open
Omit the data-mdb-parent
attribute on each .accordion-collapse
to
make accordion items stay open when another item is opened.
.accordion-body
, though the transition does limit overflow.
.accordion-body
, though the transition does limit overflow.
.accordion-body
, though the transition does limit overflow.
Accessibility
Please read the collapse accessibility section for more information.
Accordion - API
Import
Importing components depends on how your application works. If you intend to use the MDBootstrap ES
format, you must
first import the component and then initialize it with the initMDB
method. If you are going to use the UMD
format,
just import the mdb-ui-kit
package.
Usage
Via data attributes
Using the Accordion component doesn't require any additional JavaScript code - simply add
data-mdb-collapse-init
attribute to
every .accordion-button
and use other data attributes to set all options.
For ES
format, you must first import and call the initMDB
method.
Via JavaScript
CSS variables
As part of MDB’s evolving CSS variables approach, accordion now uses local CSS variables on
.accordion
for enhanced real-time customization. Values for the CSS variables are
set via Sass, so Sass customization is still supported, too.