Use the .accordion
component to provide a way to toggle the visibility of content. Be sure to add aria-expanded
to the control element. This attribute explicitly conveys the current state of the collapsible element tied to the control to screen readers and similar assistive technologies.
If the collapsible element is closed by default, the attribute on the control element should have a value of aria-expanded="false"
. If you've set the collapsible element to be open by default using the show
class, set aria-expanded="true"
on the control instead.
Learn more about this plugin on Bootstrap's official documentation.
Default Accordion
data-bs-toggle="collapse"
and a data-bs-target
to the element to automatically assign control of one or more collapsible elements. The data-bs-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
. To add accordion-like group management to a collapsible area, add the data attribute
data-parent="#selector"
. Refer to the demo to see this in action.
Accordions work well inside forms and modals, helping break down complex inputs into manageable steps.
Instead of overwhelming users with long forms, collapsible sections allow for a more progressive disclosure approach.
Accordion Outline
.accordion-outline
to .accordion
The Bootstrap Accordion component allows users to toggle between sections of content in a collapsible manner.
Each accordion item contains a header and a body. The header triggers the collapse behavior, while the body contains the actual content.
Accordion Clean layout
.accordion-clean
to .accordion
collapse.js
plugin to manage this behavior, ensuring smooth transitions and accessibility. The accordion structure supports custom styles, such as different background colors, border-radius adjustments, and shadow effects. data-bs-parent="false"
. Accordion active state icons
.collapse
state using the classes .collapsed-reveal
and .collapsed-hidden
Make sure the
.collapsed-*
classes are inside the data-toggle="collapse"
element or adjacent to it
.collapse('toggle')
allow developers to open, close, or update accordion elements dynamically via JavaScript. aria-expanded
and aria-controls
, ensuring screen readers can navigate the accordion efficiently. Accordion hover
.accordion-hover
to .accordion
Bootstrap Accordion allows extensive customization using CSS variables and utility classes. You can modify backgrounds, borders, typography, and spacing to match your website’s design system.
For example, applying bg-primary text-white
to an accordion header gives it a bold, standout appearance. Additionally, you can tweak data-bs-theme="dark"
to create a sleek, modern dark mode version.
Icons can be added to accordion headers to indicate expansion and collapse actions. Bootstrap provides built-in icons from Bootstrap Icons, Font Awesome, or custom SVGs for this purpose.
For instance, using bi-chevron-down
and toggling classes dynamically can enhance user interaction. These visual indicators improve clarity and provide a better UX for touch-based navigation.
Placing an accordion inside a Bootstrap Card can enhance the structure and readability of content. This combination is often used for pricing tables, user profiles, or expandable content sections.
Cards provide additional padding, shadows, and borders, making the accordion feel more polished and refined. Applying card-header
styles to the accordion title further integrates the two seamlessly.