Bootstrap Accordion: 16 Examples, From FAQ to Nested

Long FAQ pages and settings screens get unwieldy fast, and a Bootstrap accordion is the usual fix. It runs entirely on the Collapse plugin, so the basic version needs no script of your own.

Below are 16 Bootstrap accordion examples you can copy, followed by a guide to the markup, open states, the JavaScript API, styling and the Bootstrap 4 to 5 changes.

By Bogdan Sandu ยท Updated October 29, 2026

Every example runs on Bootstrap 5.3.8 from the jsDelivr CDN. Add these tags to your page, then paste an example's HTML, CSS and JS.

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-sRIl4kxILFvY47J16cr9ZwB07vP4J8+LH7qKQnuqkuIAvNWLzeN8tE5YBujZqJLB" crossorigin="anonymous">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.13.2/font/bootstrap-icons.min.css" rel="stylesheet" integrity="sha384-nWN3KqaaVcbEsCjLSV+2jMjh62Iny/+mN3srM8TZeM8N6aj7eDl5wwYggjAJ4/sJ" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/js/bootstrap.bundle.min.js" integrity="sha384-FKyoEForCGlyvwx9Hj09JcYn3nv7wiPVlz7YYwJrWVcXK/BmnVDxM+D2scQbITxI" crossorigin="anonymous"></script>

Everyday accordions

FAQ blocks, product details, pricing questions and grouped notifications. All four run on data attributes alone: data-bs-toggle, data-bs-target and, where only one panel should stay open, data-bs-parent.

Help center FAQ with accordion-flush

  • accordion-flush
  • data-bs-parent
  • card
  • --bs-accordion-btn-padding-x

Click a header, or tab to it and press Enter or Space.

A flush accordion inside a card, so the card supplies the outer border and the accordion items only draw the lines between questions. Every panel carries data-bs-parent pointing at the accordion id, which keeps one answer open at a time. The custom CSS only widens the horizontal padding through two accordion variables so the questions line up with the card title.

View code
<div class="card shadow-sm border-0 bac-faq">
  <div class="card-body px-4 pt-4 pb-2">
    <h3 class="h5 mb-1">Shipping questions</h3>
    <p class="text-body-secondary small mb-0">Answers from the Packwise support team, checked every week.</p>
  </div>
  <div class="accordion accordion-flush" id="bac-faq">
    <div class="accordion-item">
      <h4 class="accordion-header">
        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-faq-1" aria-expanded="false" aria-controls="bac-faq-1">How long does standard delivery take?</button>
      </h4>
      <div id="bac-faq-1" class="accordion-collapse collapse" data-bs-parent="#bac-faq">
        <div class="accordion-body">Three to five working days inside the country. Orders placed before 2 pm leave the warehouse the same day, and you get a tracking link as soon as the courier scans the parcel.</div>
      </div>
    </div>
    <div class="accordion-item">
      <h4 class="accordion-header">
        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-faq-2" aria-expanded="false" aria-controls="bac-faq-2">Can I change the delivery address after ordering?</button>
      </h4>
      <div id="bac-faq-2" class="accordion-collapse collapse" data-bs-parent="#bac-faq">
        <div class="accordion-body">Yes, until the order is packed. Open the order in your account and choose <strong>Edit address</strong>. Once the label is printed, the courier can still redirect it for a small fee.</div>
      </div>
    </div>
    <div class="accordion-item">
      <h4 class="accordion-header">
        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-faq-3" aria-expanded="false" aria-controls="bac-faq-3">Do you ship to PO boxes?</button>
      </h4>
      <div id="bac-faq-3" class="accordion-collapse collapse" data-bs-parent="#bac-faq">
        <div class="accordion-body">Standard parcels can go to a PO box. Furniture and anything over 20 kg needs a street address, because those orders travel with a two-person crew.</div>
      </div>
    </div>
    <div class="accordion-item">
      <h4 class="accordion-header">
        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-faq-4" aria-expanded="false" aria-controls="bac-faq-4">What happens if I am not home?</button>
      </h4>
      <div id="bac-faq-4" class="accordion-collapse collapse" data-bs-parent="#bac-faq">
        <div class="accordion-body">The courier leaves a card and tries again the next working day. After two attempts the parcel waits at the nearest pickup point for seven days.</div>
      </div>
    </div>
  </div>
  <div class="card-footer bg-transparent small text-body-secondary px-4 py-3">Still stuck? <a href="#">Message support</a> and we reply within a day.</div>
</div>

Always-open product details

  • no data-bs-parent
  • .show on load
  • aria-expanded="true"
  • list-unstyled

Click a header, or tab to it and press Enter or Space.

The always-open variant: no panel has data-bs-parent, so shoppers can keep fit and care notes open side by side. Two panels start open, which means .show on the collapse element plus a button without .collapsed and with aria-expanded="true". The CSS sets a calmer active state through --bs-accordion-active-bg and --bs-accordion-active-color.

View code
<div class="bac-prod">
  <h3 class="h5 mb-1">Harbor Rain Shell</h3>
  <p class="text-body-secondary mb-3">$219 <span class="mx-1" aria-hidden="true">/</span> Recycled 3-layer nylon</p>
  <div class="accordion bac-prod-acc" id="bac-prod">
    <div class="accordion-item">
      <h4 class="accordion-header">
        <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#bac-prod-fit" aria-expanded="true" aria-controls="bac-prod-fit">Size and fit</button>
      </h4>
      <div id="bac-prod-fit" class="accordion-collapse collapse show">
        <div class="accordion-body">
          <ul class="list-unstyled mb-0 small">
            <li class="mb-1">Regular fit with room for a fleece underneath</li>
            <li class="mb-1">Model is 183 cm and wears a medium</li>
            <li>Back length 76 cm on a medium</li>
          </ul>
        </div>
      </div>
    </div>
    <div class="accordion-item">
      <h4 class="accordion-header">
        <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#bac-prod-care" aria-expanded="true" aria-controls="bac-prod-care">Materials and care</button>
      </h4>
      <div id="bac-prod-care" class="accordion-collapse collapse show">
        <div class="accordion-body small">Machine wash cold, hang to dry. Tumble dry low for 20 minutes once a season to refresh the water repellent finish.</div>
      </div>
    </div>
    <div class="accordion-item">
      <h4 class="accordion-header">
        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-prod-ship" aria-expanded="false" aria-controls="bac-prod-ship">Shipping and returns</button>
      </h4>
      <div id="bac-prod-ship" class="accordion-collapse collapse">
        <div class="accordion-body small">Free shipping over $100. Return unworn items within 60 days with the prepaid label in the box.</div>
      </div>
    </div>
  </div>
</div>

Pricing FAQ in a two-column layout

  • row / col-md-*
  • data-bs-parent
  • sticky-md-top
  • btn-outline-dark

Click a header, or tab to it and press Enter or Space.

A grid row puts the section intro and a contact button in a narrow column and the accordion in the wide one, then stacks them below 768px. The accordion is the default single-open setup with data-bs-parent. Custom CSS sets the button font weight and a neutral active state so the block fits a pricing page instead of looking like a docs example.

View code
<section class="bac-price" aria-labelledby="bac-price-title">
  <div class="row g-4">
    <div class="col-md-5">
      <h3 class="h4 mb-2" id="bac-price-title">Plans and billing questions</h3>
      <p class="text-body-secondary mb-3">Everything about trials, invoices and switching plans in Ledgerly. Need a custom contract for more than 50 seats?</p>
      <a href="#" class="btn btn-outline-dark">Talk to sales</a>
    </div>
    <div class="col-md-7">
      <div class="accordion bac-price-acc" id="bac-price">
        <div class="accordion-item">
          <h4 class="accordion-header">
            <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#bac-price-1" aria-expanded="true" aria-controls="bac-price-1">Is there a free trial?</button>
          </h4>
          <div id="bac-price-1" class="accordion-collapse collapse show" data-bs-parent="#bac-price">
            <div class="accordion-body">Every plan starts with 14 days free and no card. At the end of the trial you pick a plan or the workspace switches to read-only.</div>
          </div>
        </div>
        <div class="accordion-item">
          <h4 class="accordion-header">
            <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-price-2" aria-expanded="false" aria-controls="bac-price-2">Can I switch plans later?</button>
          </h4>
          <div id="bac-price-2" class="accordion-collapse collapse" data-bs-parent="#bac-price">
            <div class="accordion-body">Upgrades apply right away and we charge the difference for the days left in the cycle. Downgrades start at the next renewal.</div>
          </div>
        </div>
        <div class="accordion-item">
          <h4 class="accordion-header">
            <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-price-3" aria-expanded="false" aria-controls="bac-price-3">Do you issue VAT invoices?</button>
          </h4>
          <div id="bac-price-3" class="accordion-collapse collapse" data-bs-parent="#bac-price">
            <div class="accordion-body">Yes. Add your VAT number under Billing and every invoice from then on shows it, with reverse charge applied where it is due.</div>
          </div>
        </div>
        <div class="accordion-item">
          <h4 class="accordion-header">
            <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-price-4" aria-expanded="false" aria-controls="bac-price-4">Do nonprofits get a discount?</button>
          </h4>
          <div id="bac-price-4" class="accordion-collapse collapse" data-bs-parent="#bac-price">
            <div class="accordion-body">Registered nonprofits and schools get 40 percent off any annual plan. Send us your registration document from the billing page.</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</section>

Notification groups with icons and badges

  • Bootstrap Icons
  • badge rounded-pill
  • list-group-flush
  • visually-hidden

Click a header, or tab to it and press Enter or Space.

Icons and badges sit inside the accordion button, so the heading still contains only the button, as the ARIA accordion pattern asks. Icons are aria-hidden, and each badge has visually-hidden text so a screen reader hears 4 unread instead of a bare number. The panels hold flush list groups, and the CSS adds the square icon tile.

View code
<div class="accordion shadow-sm bac-inbox" id="bac-inbox">
  <div class="accordion-item">
    <h3 class="accordion-header">
      <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-inbox-men" aria-expanded="false" aria-controls="bac-inbox-men">
        <span class="bac-inbox-tile bg-primary-subtle text-primary-emphasis"><i class="bi bi-at" aria-hidden="true"></i></span>
        <span class="me-auto">Mentions</span>
        <span class="badge rounded-pill text-bg-danger me-2">4<span class="visually-hidden"> unread</span></span>
      </button>
    </h3>
    <div id="bac-inbox-men" class="accordion-collapse collapse" data-bs-parent="#bac-inbox">
      <div class="list-group list-group-flush">
        <a href="#" class="list-group-item list-group-item-action"><span class="fw-semibold">Rina Okafor</span> mentioned you in Q4 launch plan <span class="d-block small text-body-secondary">12 min ago</span></a>
        <a href="#" class="list-group-item list-group-item-action"><span class="fw-semibold">Tom Varga</span> asked for your review on Pricing copy <span class="d-block small text-body-secondary">1 h ago</span></a>
      </div>
    </div>
  </div>
  <div class="accordion-item">
    <h3 class="accordion-header">
      <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-inbox-app" aria-expanded="false" aria-controls="bac-inbox-app">
        <span class="bac-inbox-tile bg-success-subtle text-success-emphasis"><i class="bi bi-check2-circle" aria-hidden="true"></i></span>
        <span class="me-auto">Approvals</span>
        <span class="badge rounded-pill text-bg-warning me-2">2<span class="visually-hidden"> waiting</span></span>
      </button>
    </h3>
    <div id="bac-inbox-app" class="accordion-collapse collapse" data-bs-parent="#bac-inbox">
      <div class="list-group list-group-flush">
        <a href="#" class="list-group-item list-group-item-action">Travel budget for the Berlin offsite <span class="d-block small text-body-secondary">Requested by Mia Lund</span></a>
        <a href="#" class="list-group-item list-group-item-action">New laptop for the design team <span class="d-block small text-body-secondary">Requested by Ken Ito</span></a>
      </div>
    </div>
  </div>
  <div class="accordion-item">
    <h3 class="accordion-header">
      <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-inbox-com" aria-expanded="false" aria-controls="bac-inbox-com">
        <span class="bac-inbox-tile bg-info-subtle text-info-emphasis"><i class="bi bi-chat-left-text" aria-hidden="true"></i></span>
        <span class="me-auto">Comments</span>
        <span class="badge rounded-pill text-bg-light border me-2">0<span class="visually-hidden"> new</span></span>
      </button>
    </h3>
    <div id="bac-inbox-com" class="accordion-collapse collapse" data-bs-parent="#bac-inbox">
      <div class="accordion-body small text-body-secondary">You are all caught up. New comments on your files show up here.</div>
    </div>
  </div>
</div>

Accordions inside real layouts

Nested groups, settings forms, order rows with a summary line and a course sidebar. The accordion body takes almost any HTML, so forms, tables and list groups all fit inside a panel.

Nested accordion for a knowledge base

  • nested .accordion
  • own data-bs-parent per level
  • accordion-flush
  • border rounded

Open a panel and use the controls inside it.

An inner flush accordion lives inside the accordion-body of the Integrations panel. It has its own id, and the inner panels point their data-bs-parent at that id, so inner questions close each other without touching the outer level. Bootstrap 5.3.8 scopes the parent lookup with :scope, which is the fix that shipped in 5.1.2 for nested grouping.

View code
<div class="accordion bac-kb" id="bac-kb">
  <div class="accordion-item">
    <h3 class="accordion-header">
      <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-kb-start" aria-expanded="false" aria-controls="bac-kb-start">Getting started</button>
    </h3>
    <div id="bac-kb-start" class="accordion-collapse collapse" data-bs-parent="#bac-kb">
      <div class="accordion-body">Create a workspace, invite two teammates and connect your first data source. Most teams finish setup in about ten minutes.</div>
    </div>
  </div>
  <div class="accordion-item">
    <h3 class="accordion-header">
      <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-kb-int" aria-expanded="false" aria-controls="bac-kb-int">Integrations</button>
    </h3>
    <div id="bac-kb-int" class="accordion-collapse collapse" data-bs-parent="#bac-kb">
      <div class="accordion-body">
        <p class="small text-body-secondary mb-2">Three ways to connect Tidepool to the tools you already use.</p>
        <div class="accordion accordion-flush border rounded bac-kb-inner" id="bac-kb-sub">
          <div class="accordion-item">
            <h4 class="accordion-header">
              <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-kb-cal" aria-expanded="false" aria-controls="bac-kb-cal">Calendar sync</button>
            </h4>
            <div id="bac-kb-cal" class="accordion-collapse collapse" data-bs-parent="#bac-kb-sub">
              <div class="accordion-body small">Paste your calendar feed address under Settings, Calendar. Events refresh every 15 minutes.</div>
            </div>
          </div>
          <div class="accordion-item">
            <h4 class="accordion-header">
              <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-kb-chat" aria-expanded="false" aria-controls="bac-kb-chat">Team chat alerts</button>
            </h4>
            <div id="bac-kb-chat" class="accordion-collapse collapse" data-bs-parent="#bac-kb-sub">
              <div class="accordion-body small">Pick a channel and the events you care about. Alerts include a link back to the record.</div>
            </div>
          </div>
          <div class="accordion-item">
            <h4 class="accordion-header">
              <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-kb-hook" aria-expanded="false" aria-controls="bac-kb-hook">Webhooks</button>
            </h4>
            <div id="bac-kb-hook" class="accordion-collapse collapse" data-bs-parent="#bac-kb-sub">
              <div class="accordion-body small">Add an endpoint, choose events and copy the signing secret. Failed deliveries retry five times over an hour.</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="accordion-item">
    <h3 class="accordion-header">
      <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-kb-sec" aria-expanded="false" aria-controls="bac-kb-sec">Security and access</button>
    </h3>
    <div id="bac-kb-sec" class="accordion-collapse collapse" data-bs-parent="#bac-kb">
      <div class="accordion-body">Turn on single sign-on, require two-factor sign-in and review the audit log from the Admin area.</div>
    </div>
  </div>
</div>

Settings panels with form controls

  • form-switch
  • form-select
  • role="status"
  • submit + preventDefault

Open a panel and use the controls inside it.

Each panel body holds its own small form with labelled inputs, a select and form-switch checkboxes, which shows how much a panel can carry. The submit listener calls preventDefault and writes a confirmation into a role="status" element with textContent. Custom CSS only adds the subtitle under each header label.

View code
<div class="accordion bac-set" id="bac-set">
  <div class="accordion-item">
    <h3 class="accordion-header">
      <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#bac-set-prof" aria-expanded="true" aria-controls="bac-set-prof">
        <span>Profile<span class="bac-set-sub">Name and time zone</span></span>
      </button>
    </h3>
    <div id="bac-set-prof" class="accordion-collapse collapse show" data-bs-parent="#bac-set">
      <div class="accordion-body">
        <form class="bac-set-form" novalidate>
          <div class="mb-3">
            <label for="bac-set-name" class="form-label">Display name</label>
            <input type="text" class="form-control" id="bac-set-name" value="Dana Whitfield" autocomplete="name">
          </div>
          <div class="mb-3">
            <label for="bac-set-tz" class="form-label">Time zone</label>
            <select class="form-select" id="bac-set-tz">
              <option>UTC</option>
              <option selected>Central European Time</option>
              <option>Eastern Time (US)</option>
            </select>
          </div>
          <div class="d-flex align-items-center gap-3">
            <button type="submit" class="btn btn-primary">Save profile</button>
            <span class="small text-success-emphasis bac-set-msg" role="status"></span>
          </div>
        </form>
      </div>
    </div>
  </div>
  <div class="accordion-item">
    <h3 class="accordion-header">
      <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-set-notif" aria-expanded="false" aria-controls="bac-set-notif">
        <span>Notifications<span class="bac-set-sub">Email and push alerts</span></span>
      </button>
    </h3>
    <div id="bac-set-notif" class="accordion-collapse collapse" data-bs-parent="#bac-set">
      <div class="accordion-body">
        <form class="bac-set-form" novalidate>
          <div class="form-check form-switch mb-2">
            <input class="form-check-input" type="checkbox" role="switch" id="bac-set-digest" checked>
            <label class="form-check-label" for="bac-set-digest">Weekly summary email</label>
          </div>
          <div class="form-check form-switch mb-2">
            <input class="form-check-input" type="checkbox" role="switch" id="bac-set-push">
            <label class="form-check-label" for="bac-set-push">Push alerts for mentions</label>
          </div>
          <div class="form-check form-switch mb-3">
            <input class="form-check-input" type="checkbox" role="switch" id="bac-set-news">
            <label class="form-check-label" for="bac-set-news">Product news</label>
          </div>
          <div class="d-flex align-items-center gap-3">
            <button type="submit" class="btn btn-primary" id="bac-set-notif-save">Save alerts</button>
            <span class="small text-success-emphasis bac-set-msg" role="status" id="bac-set-notif-msg"></span>
          </div>
        </form>
      </div>
    </div>
  </div>
  <div class="accordion-item">
    <h3 class="accordion-header">
      <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-set-priv" aria-expanded="false" aria-controls="bac-set-priv">
        <span>Privacy<span class="bac-set-sub">Who can see your profile</span></span>
      </button>
    </h3>
    <div id="bac-set-priv" class="accordion-collapse collapse" data-bs-parent="#bac-set">
      <div class="accordion-body">
        <form class="bac-set-form" novalidate>
          <fieldset class="mb-3">
            <legend class="form-label fs-6">Profile visibility</legend>
            <div class="form-check">
              <input class="form-check-input" type="radio" name="bac-set-vis" id="bac-set-vis-team" checked>
              <label class="form-check-label" for="bac-set-vis-team">My team only</label>
            </div>
            <div class="form-check">
              <input class="form-check-input" type="radio" name="bac-set-vis" id="bac-set-vis-org">
              <label class="form-check-label" for="bac-set-vis-org">Everyone in the company</label>
            </div>
          </fieldset>
          <div class="d-flex align-items-center gap-3">
            <button type="submit" class="btn btn-primary">Save privacy</button>
            <span class="small text-success-emphasis bac-set-msg" role="status"></span>
          </div>
        </form>
      </div>
    </div>
  </div>
</div>

Order history with summary rows

  • flex summary in accordion-button
  • badge text-bg-*
  • table-sm
  • btn-sm

Open a panel and use the controls inside it.

Each header button carries a summary row: order number, date, status badge and total, laid out with a wrapping flex container so it reflows on a phone. The panel shows the line items in a small table and the order actions. Custom CSS defines the summary row and keeps the total aligned to the right on wider screens.

View code
<div class="bac-ord">
  <h3 class="h5 mb-3">Your orders</h3>
  <div class="accordion" id="bac-ord">
    <div class="accordion-item">
      <h4 class="accordion-header">
        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-ord-1" aria-expanded="false" aria-controls="bac-ord-1">
          <span class="bac-ord-sum">
            <span class="fw-semibold">#40218</span>
            <span class="small text-body-secondary">Oct 21, 2026</span>
            <span class="badge text-bg-success">Delivered</span>
            <span class="bac-ord-total">$128.40</span>
          </span>
        </button>
      </h4>
      <div id="bac-ord-1" class="accordion-collapse collapse" data-bs-parent="#bac-ord">
        <div class="accordion-body">
          <table class="table table-sm small mb-3">
            <caption class="visually-hidden">Items in order 40218</caption>
            <thead><tr><th scope="col">Item</th><th scope="col" class="text-end">Qty</th><th scope="col" class="text-end">Price</th></tr></thead>
            <tbody>
              <tr><td>Stoneware mug, sand</td><td class="text-end">2</td><td class="text-end">$36.00</td></tr>
              <tr><td>Linen tea towel set</td><td class="text-end">1</td><td class="text-end">$24.40</td></tr>
              <tr><td>Oak serving board</td><td class="text-end">1</td><td class="text-end">$68.00</td></tr>
            </tbody>
          </table>
          <div class="d-flex flex-wrap gap-2">
            <a href="#" class="btn btn-sm btn-outline-secondary">Download invoice</a>
            <a href="#" class="btn btn-sm btn-outline-secondary">Return items</a>
          </div>
        </div>
      </div>
    </div>
    <div class="accordion-item">
      <h4 class="accordion-header">
        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-ord-2" aria-expanded="false" aria-controls="bac-ord-2">
          <span class="bac-ord-sum">
            <span class="fw-semibold">#40377</span>
            <span class="small text-body-secondary">Oct 26, 2026</span>
            <span class="badge text-bg-primary">Shipped</span>
            <span class="bac-ord-total">$54.90</span>
          </span>
        </button>
      </h4>
      <div id="bac-ord-2" class="accordion-collapse collapse" data-bs-parent="#bac-ord">
        <div class="accordion-body">
          <p class="small mb-2">Out with the courier. Expected <strong>Thursday, Oct 29</strong>.</p>
          <div class="progress mb-3" role="progressbar" aria-label="Delivery progress" aria-valuenow="70" aria-valuemin="0" aria-valuemax="100" style="height: .5rem">
            <div class="progress-bar" style="width: 70%"></div>
          </div>
          <a href="#" class="btn btn-sm btn-primary">Track package</a>
        </div>
      </div>
    </div>
    <div class="accordion-item">
      <h4 class="accordion-header">
        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-ord-3" aria-expanded="false" aria-controls="bac-ord-3">
          <span class="bac-ord-sum">
            <span class="fw-semibold">#40402</span>
            <span class="small text-body-secondary">Oct 27, 2026</span>
            <span class="badge text-bg-warning">Processing</span>
            <span class="bac-ord-total">$212.00</span>
          </span>
        </button>
      </h4>
      <div id="bac-ord-3" class="accordion-collapse collapse" data-bs-parent="#bac-ord">
        <div class="accordion-body">
          <p class="small mb-3">We are packing your order. You can still change the address or cancel until it ships.</p>
          <div class="d-flex flex-wrap gap-2">
            <a href="#" class="btn btn-sm btn-outline-secondary">Edit address</a>
            <a href="#" class="btn btn-sm btn-outline-danger">Cancel order</a>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

Course syllabus sidebar with progress

  • accordion-flush
  • progress
  • form-check in list-group
  • change event

Open a panel and use the controls inside it.

A sidebar card with a progress bar on top and one flush accordion item per module. Lessons are form-check checkboxes inside a list group, and a change listener recounts them with textContent, updating the module counters, the progress bar width and its aria-valuenow. Custom CSS styles the small counter pill in each header.

View code
<aside class="card shadow-sm bac-course" aria-label="Course syllabus">
  <div class="card-body pb-3">
    <h3 class="h6 mb-1">Responsive layouts with Bootstrap</h3>
    <p class="small text-body-secondary mb-2" id="bac-course-text">4 of 12 lessons done</p>
    <div class="progress" role="progressbar" aria-label="Course progress" aria-valuenow="33" aria-valuemin="0" aria-valuemax="100" id="bac-course-bar" style="height: .5rem">
      <div class="progress-bar bg-success" style="width: 33%"></div>
    </div>
  </div>
  <div class="accordion accordion-flush border-top bac-course-acc" id="bac-course">
    <div class="accordion-item bac-course-mod">
      <h4 class="accordion-header">
        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-course-m1" aria-expanded="false" aria-controls="bac-course-m1">Foundations <span class="bac-course-count">3/3</span></button>
      </h4>
      <div id="bac-course-m1" class="accordion-collapse collapse" data-bs-parent="#bac-course">
        <ul class="list-group list-group-flush">
          <li class="list-group-item"><div class="form-check"><input class="form-check-input" type="checkbox" id="bac-l1" checked><label class="form-check-label" for="bac-l1">Containers and breakpoints</label></div></li>
          <li class="list-group-item"><div class="form-check"><input class="form-check-input" type="checkbox" id="bac-l2" checked><label class="form-check-label" for="bac-l2">Spacing utilities</label></div></li>
          <li class="list-group-item"><div class="form-check"><input class="form-check-input" type="checkbox" id="bac-l3" checked><label class="form-check-label" for="bac-l3">Color modes</label></div></li>
        </ul>
      </div>
    </div>
    <div class="accordion-item bac-course-mod">
      <h4 class="accordion-header">
        <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#bac-course-m2" aria-expanded="true" aria-controls="bac-course-m2">Grid and columns <span class="bac-course-count">1/4</span></button>
      </h4>
      <div id="bac-course-m2" class="accordion-collapse collapse show" data-bs-parent="#bac-course">
        <ul class="list-group list-group-flush">
          <li class="list-group-item"><div class="form-check"><input class="form-check-input" type="checkbox" id="bac-l4" checked><label class="form-check-label" for="bac-l4">Rows and gutters</label></div></li>
          <li class="list-group-item"><div class="form-check"><input class="form-check-input" type="checkbox" id="bac-l5"><label class="form-check-label" for="bac-l5">Responsive columns</label></div></li>
          <li class="list-group-item"><div class="form-check"><input class="form-check-input" type="checkbox" id="bac-l6"><label class="form-check-label" for="bac-l6">Ordering and offsets</label></div></li>
          <li class="list-group-item"><div class="form-check"><input class="form-check-input" type="checkbox" id="bac-l7"><label class="form-check-label" for="bac-l7">CSS Grid mode</label></div></li>
        </ul>
      </div>
    </div>
    <div class="accordion-item bac-course-mod">
      <h4 class="accordion-header">
        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-course-m3" aria-expanded="false" aria-controls="bac-course-m3">Components <span class="bac-course-count">0/3</span></button>
      </h4>
      <div id="bac-course-m3" class="accordion-collapse collapse" data-bs-parent="#bac-course">
        <ul class="list-group list-group-flush">
          <li class="list-group-item"><div class="form-check"><input class="form-check-input" type="checkbox" id="bac-l8"><label class="form-check-label" for="bac-l8">Navbars that collapse</label></div></li>
          <li class="list-group-item"><div class="form-check"><input class="form-check-input" type="checkbox" id="bac-l9"><label class="form-check-label" for="bac-l9">Cards in a grid</label></div></li>
          <li class="list-group-item"><div class="form-check"><input class="form-check-input" type="checkbox" id="bac-l10"><label class="form-check-label" for="bac-l10">Accordions and tabs</label></div></li>
        </ul>
      </div>
    </div>
    <div class="accordion-item bac-course-mod">
      <h4 class="accordion-header">
        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-course-m4" aria-expanded="false" aria-controls="bac-course-m4">Shipping the site <span class="bac-course-count">0/2</span></button>
      </h4>
      <div id="bac-course-m4" class="accordion-collapse collapse" data-bs-parent="#bac-course">
        <ul class="list-group list-group-flush">
          <li class="list-group-item"><div class="form-check"><input class="form-check-input" type="checkbox" id="bac-l11"><label class="form-check-label" for="bac-l11">Trimming unused CSS</label></div></li>
          <li class="list-group-item"><div class="form-check"><input class="form-check-input" type="checkbox" id="bac-l12"><label class="form-check-label" for="bac-l12">Final project review</label></div></li>
        </ul>
      </div>
    </div>
  </div>
</aside>

Themed with --bs-accordion-* variables

Bootstrap 5.3 declares 21 local CSS variables on .accordion, so colors, borders, radius, padding and even the chevron icon change with a few lines of CSS and no Sass build.

Dark mode incident history

  • data-bs-theme="dark"
  • --bs-accordion-active-*
  • --bs-accordion-btn-active-icon
  • badge text-bg-*

Click a header to see the themed open state.

The stage sets data-bs-theme="dark", so the accordion picks up the dark body colors and the dark chevron from Bootstrap with no extra CSS. The custom rules swap the active state for a cyan tint and recolor the active chevron SVG to match, all through --bs-accordion-* variables on one prefixed class.

View code
<div class="bac-status">
  <div class="d-flex align-items-center gap-2 mb-3">
    <span class="bac-status-dot" aria-hidden="true"></span>
    <h3 class="h6 mb-0">All systems operational</h3>
  </div>
  <div class="accordion bac-status-acc" id="bac-status">
    <div class="accordion-item">
      <h4 class="accordion-header">
        <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#bac-status-1" aria-expanded="true" aria-controls="bac-status-1">
          <span class="me-auto">Slow API responses in EU West</span>
          <span class="badge text-bg-warning me-2">Monitoring</span>
        </button>
      </h4>
      <div id="bac-status-1" class="accordion-collapse collapse show" data-bs-parent="#bac-status">
        <div class="accordion-body small">
          <p class="mb-2"><span class="fw-semibold">14:20 UTC</span> A fix is live and response times are back under 200 ms. We are watching the region for the next hour.</p>
          <p class="mb-0 text-body-secondary"><span class="fw-semibold">13:05 UTC</span> We are seeing slow responses for about 8 percent of requests.</p>
        </div>
      </div>
    </div>
    <div class="accordion-item">
      <h4 class="accordion-header">
        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-status-2" aria-expanded="false" aria-controls="bac-status-2">
          <span class="me-auto">Delayed webhook deliveries</span>
          <span class="badge text-bg-success me-2">Resolved</span>
        </button>
      </h4>
      <div id="bac-status-2" class="accordion-collapse collapse" data-bs-parent="#bac-status">
        <div class="accordion-body small">A queue worker stalled after a deploy. Deliveries were delayed by up to 25 minutes and every event was sent once the worker restarted.</div>
      </div>
    </div>
    <div class="accordion-item">
      <h4 class="accordion-header">
        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-status-3" aria-expanded="false" aria-controls="bac-status-3">
          <span class="me-auto">Scheduled database upgrade</span>
          <span class="badge text-bg-secondary me-2">Planned</span>
        </button>
      </h4>
      <div id="bac-status-3" class="accordion-collapse collapse" data-bs-parent="#bac-status">
        <div class="accordion-body small">Sunday, Nov 1, 02:00 to 02:30 UTC. Dashboards stay readable, and writes queue up and apply after the upgrade.</div>
      </div>
    </div>
  </div>
</div>

Plus and minus icons for a bakery FAQ

  • --bs-accordion-btn-icon
  • --bs-accordion-btn-active-icon
  • --bs-accordion-btn-icon-transform
  • --bs-accordion-border-radius

Click a header to see the themed open state.

Two inline SVG data URIs replace the chevron: a plus in --bs-accordion-btn-icon and a minus in --bs-accordion-btn-active-icon. Setting --bs-accordion-btn-icon-transform to none stops Bootstrap from rotating the new icons. The warm palette, larger radius and serif question text all come from accordion variables on the prefixed class.

View code
<div class="bac-cake">
  <h3 class="bac-cake-title mb-3">Ordering a custom cake</h3>
  <div class="accordion bac-cake-acc" id="bac-cake">
    <div class="accordion-item">
      <h4 class="accordion-header">
        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-cake-1" aria-expanded="false" aria-controls="bac-cake-1">How far ahead should I order?</button>
      </h4>
      <div id="bac-cake-1" class="accordion-collapse collapse" data-bs-parent="#bac-cake">
        <div class="accordion-body">Give us at least five days for a single-tier cake and two weeks for wedding cakes. In December we book up about a month out.</div>
      </div>
    </div>
    <div class="accordion-item">
      <h4 class="accordion-header">
        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-cake-2" aria-expanded="false" aria-controls="bac-cake-2">Can you bake without gluten or dairy?</button>
      </h4>
      <div id="bac-cake-2" class="accordion-collapse collapse" data-bs-parent="#bac-cake">
        <div class="accordion-body">Yes for both. Our kitchen also handles wheat and nuts, so we cannot promise a cake free from traces for severe allergies.</div>
      </div>
    </div>
    <div class="accordion-item">
      <h4 class="accordion-header">
        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-cake-3" aria-expanded="false" aria-controls="bac-cake-3">Do you deliver?</button>
      </h4>
      <div id="bac-cake-3" class="accordion-collapse collapse" data-bs-parent="#bac-cake">
        <div class="accordion-body">Within 15 km of the shop for a flat $18. Tiered cakes are delivered and set up by one of our bakers.</div>
      </div>
    </div>
  </div>
</div>

Separated card items for a hosting help page

  • one .accordion per item
  • data-bs-parent on a wrapper
  • vstack gap-2
  • --bs-accordion-border-radius

Click a header to see the themed open state.

Each question is its own single-item .accordion, so every card gets all four rounded corners from Bootstrap without fighting the first-of-type and last-of-type rules. The panels still close each other because data-bs-parent points at the shared vstack wrapper, which is all the parent option needs. The green theme is set once on the wrapper through accordion variables.

View code
<div class="vstack gap-2 bac-dns" id="bac-dns">
  <div class="accordion shadow-sm">
    <div class="accordion-item">
      <h3 class="accordion-header">
        <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#bac-dns-1" aria-expanded="true" aria-controls="bac-dns-1">How long do DNS changes take?</button>
      </h3>
      <div id="bac-dns-1" class="accordion-collapse collapse show" data-bs-parent="#bac-dns">
        <div class="accordion-body">Most resolvers pick up a change within an hour. Lower the TTL to 300 seconds a day before a move and the switch is almost instant.</div>
      </div>
    </div>
  </div>
  <div class="accordion shadow-sm">
    <div class="accordion-item">
      <h3 class="accordion-header">
        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-dns-2" aria-expanded="false" aria-controls="bac-dns-2">Where do I point my domain?</button>
      </h3>
      <div id="bac-dns-2" class="accordion-collapse collapse" data-bs-parent="#bac-dns">
        <div class="accordion-body">Add an A record for the root domain and a CNAME for www. Both values are on the Domains page of your Fernhost dashboard.</div>
      </div>
    </div>
  </div>
  <div class="accordion shadow-sm">
    <div class="accordion-item">
      <h3 class="accordion-header">
        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-dns-3" aria-expanded="false" aria-controls="bac-dns-3">Is the SSL certificate free?</button>
      </h3>
      <div id="bac-dns-3" class="accordion-collapse collapse" data-bs-parent="#bac-dns">
        <div class="accordion-body">Yes. A certificate is issued automatically once the domain points to us, and it renews on its own before it expires.</div>
      </div>
    </div>
  </div>
</div>

Editorial careers FAQ with an arrow icon

  • --bs-accordion-bg: transparent
  • --bs-accordion-btn-padding-x: 0
  • custom arrow icon
  • rotate(90deg)

Click a header to see the themed open state.

A borderless, magazine-style accordion: transparent backgrounds, almost no horizontal padding, square corners and a thin rule between items, all set with accordion variables. A right-pointing arrow replaces the chevron and --bs-accordion-btn-icon-transform turns it 90 degrees when a panel opens. Only the serif type and the cream panel are extra CSS.

View code
<div class="bac-ed">
  <h3 class="bac-ed-title">Working at Fieldnote Studio</h3>
  <div class="accordion accordion-flush bac-ed-acc" id="bac-ed">
    <div class="accordion-item">
      <h4 class="accordion-header">
        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-ed-1" aria-expanded="false" aria-controls="bac-ed-1">Do you hire remote designers?</button>
      </h4>
      <div id="bac-ed-1" class="accordion-collapse collapse" data-bs-parent="#bac-ed">
        <div class="accordion-body">Yes, anywhere within three hours of Lisbon time. We meet in person twice a year and cover the travel.</div>
      </div>
    </div>
    <div class="accordion-item">
      <h4 class="accordion-header">
        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-ed-2" aria-expanded="false" aria-controls="bac-ed-2">What does the interview look like?</button>
      </h4>
      <div id="bac-ed-2" class="accordion-collapse collapse" data-bs-parent="#bac-ed">
        <div class="accordion-body">A portfolio call, a paid half-day project and a conversation with two people you would work with. No whiteboard puzzles.</div>
      </div>
    </div>
    <div class="accordion-item">
      <h4 class="accordion-header">
        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-ed-3" aria-expanded="false" aria-controls="bac-ed-3">Is there a learning budget?</button>
      </h4>
      <div id="bac-ed-3" class="accordion-collapse collapse" data-bs-parent="#bac-ed">
        <div class="accordion-body">Every person gets 1,500 euros a year for books, courses and conferences, plus one Friday a month for side projects.</div>
      </div>
    </div>
  </div>
</div>

JavaScript API and events

Expand and collapse everything, filter panels with a search box, open a panel from a link and block a step until the previous one is valid. Each script uses bootstrap.Collapse.getOrCreateInstance(), the collapse events and textContent only.

Expand all and collapse all buttons

  • bootstrap.Collapse.getOrCreateInstance
  • { toggle: false }
  • shown.bs.collapse
  • hidden.bs.collapse

Click Expand all, then Collapse all.

An always-open itinerary with two toolbar buttons. Each one loops over the panels and calls getOrCreateInstance(panel, { toggle: false }) followed by show() or hide(), and the plugin itself updates aria-expanded and .collapsed on every header. Listeners on shown.bs.collapse and hidden.bs.collapse keep the open counter in a polite live region up to date.

View code
<div class="bac-trip">
  <div class="d-flex flex-wrap align-items-center justify-content-between gap-2 mb-3">
    <div>
      <h3 class="h5 mb-0">Atlantic coast, four days</h3>
      <p class="small text-body-secondary mb-0" id="bac-trip-count" aria-live="polite">0 of 4 days open</p>
    </div>
    <div class="btn-group btn-group-sm" role="group" aria-label="Itinerary panels">
      <button type="button" class="btn btn-outline-primary" id="bac-trip-open" aria-controls="bac-trip-1 bac-trip-2 bac-trip-3 bac-trip-4">Expand all</button>
      <button type="button" class="btn btn-outline-primary" id="bac-trip-close" aria-controls="bac-trip-1 bac-trip-2 bac-trip-3 bac-trip-4">Collapse all</button>
    </div>
  </div>
  <div class="accordion" id="bac-trip">
    <div class="accordion-item">
      <h4 class="accordion-header">
        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-trip-1" aria-expanded="false" aria-controls="bac-trip-1">Arrival and old town walk</button>
      </h4>
      <div id="bac-trip-1" class="accordion-collapse collapse">
        <div class="accordion-body small">Check in by 3 pm, then a two-hour walk through the hill streets with a stop for grilled sardines.</div>
      </div>
    </div>
    <div class="accordion-item">
      <h4 class="accordion-header">
        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-trip-2" aria-expanded="false" aria-controls="bac-trip-2">Palaces in the hills</button>
      </h4>
      <div id="bac-trip-2" class="accordion-collapse collapse">
        <div class="accordion-body small">Early train to the hills, two palaces before lunch and a forest trail back down to the station.</div>
      </div>
    </div>
    <div class="accordion-item">
      <h4 class="accordion-header">
        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-trip-3" aria-expanded="false" aria-controls="bac-trip-3">Coast road by bike</button>
      </h4>
      <div id="bac-trip-3" class="accordion-collapse collapse">
        <div class="accordion-body small">An easy 24 km ride along the sea wall with e-bikes included. Swim stop at the second beach.</div>
      </div>
    </div>
    <div class="accordion-item">
      <h4 class="accordion-header">
        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-trip-4" aria-expanded="false" aria-controls="bac-trip-4">Market morning and departure</button>
      </h4>
      <div id="bac-trip-4" class="accordion-collapse collapse">
        <div class="accordion-body small">Breakfast at the covered market, free time for shopping and an airport transfer at 2 pm.</div>
      </div>
    </div>
  </div>
</div>

Search that filters and opens matching answers

  • textContent search
  • getOrCreateInstance().show()
  • d-none
  • aria-live

Type refund, invoice or card into the search box.

An input listener compares the query with each item textContent, hides the items that do not match with d-none and opens the ones that do through getOrCreateInstance(panel, { toggle: false }).show(). Clearing the box restores every item and closes them again. The result count goes into an aria-live region so screen reader users hear how many answers are left.

View code
<div class="bac-help">
  <label for="bac-help-q" class="form-label fw-semibold">Search billing help</label>
  <input type="search" class="form-control mb-2" id="bac-help-q" placeholder="Try refund or invoice" autocomplete="off" aria-describedby="bac-help-count">
  <p class="small text-body-secondary mb-3" id="bac-help-count" aria-live="polite">5 answers</p>
  <div class="accordion" id="bac-help">
    <div class="accordion-item">
      <h3 class="accordion-header">
        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-help-1" aria-expanded="false" aria-controls="bac-help-1">How do refunds work?</button>
      </h3>
      <div id="bac-help-1" class="accordion-collapse collapse">
        <div class="accordion-body small">Annual plans can get a full refund within 30 days. The money goes back to the original card in five to ten days.</div>
      </div>
    </div>
    <div class="accordion-item">
      <h3 class="accordion-header">
        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-help-2" aria-expanded="false" aria-controls="bac-help-2">Where can I download invoices?</button>
      </h3>
      <div id="bac-help-2" class="accordion-collapse collapse">
        <div class="accordion-body small">Open Billing, then History. Every invoice is a PDF, and you can add a purchase order number before you download it.</div>
      </div>
    </div>
    <div class="accordion-item">
      <h3 class="accordion-header">
        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-help-3" aria-expanded="false" aria-controls="bac-help-3">How do I update my card?</button>
      </h3>
      <div id="bac-help-3" class="accordion-collapse collapse">
        <div class="accordion-body small">Choose Payment method under Billing and add the new card. The old one is removed after the next successful charge.</div>
      </div>
    </div>
    <div class="accordion-item">
      <h3 class="accordion-header">
        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-help-4" aria-expanded="false" aria-controls="bac-help-4">Why was my payment declined?</button>
      </h3>
      <div id="bac-help-4" class="accordion-collapse collapse">
        <div class="accordion-body small">Usually the bank blocked an online charge or the card expired. We retry three times over a week and email you each time, with a refund for any double charge.</div>
      </div>
    </div>
    <div class="accordion-item">
      <h3 class="accordion-header">
        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#bac-help-5" aria-expanded="false" aria-controls="bac-help-5">Can I pay by bank transfer?</button>
      </h3>
      <div id="bac-help-5" class="accordion-collapse collapse">
        <div class="accordion-body small">Yes, on annual plans over $1,000. Ask for a transfer invoice and pay within 30 days.</div>
      </div>
    </div>
  </div>
  <p class="small text-body-secondary mt-3 mb-0 d-none" id="bac-help-none">No answers match. Try a shorter word.</p>
</div>

Checkout steps that block skipping ahead

  • show.bs.collapse + preventDefault()
  • checkValidity()
  • was-validated
  • getOrCreateInstance().show()

Click Delivery first, then fill in the contact step and press Continue.

The later panels listen for show.bs.collapse and call preventDefault() until the step before them is complete, so a click on a locked header does nothing except show a short message. The contact form uses the Bootstrap validation pattern: novalidate, checkValidity() and .was-validated. A valid submit marks the step done and opens the next panel through getOrCreateInstance().show().

View code
<div class="bac-co">
  <div class="accordion" id="bac-co">
    <div class="accordion-item">
      <h3 class="accordion-header">
        <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#bac-co-contact" aria-expanded="true" aria-controls="bac-co-contact">
          <span class="me-auto">Contact details</span>
          <span class="badge text-bg-success me-2 d-none" id="bac-co-contact-done">Done</span>
        </button>
      </h3>
      <div id="bac-co-contact" class="accordion-collapse collapse show" data-bs-parent="#bac-co">
        <div class="accordion-body">
          <form id="bac-co-form" novalidate>
            <div class="mb-3">
              <label for="bac-co-name" class="form-label">Full name</label>
              <input type="text" class="form-control" id="bac-co-name" autocomplete="name" required>
              <div class="invalid-feedback">Enter the name for the delivery.</div>
            </div>
            <div class="mb-3">
              <label for="bac-co-email" class="form-label">Email</label>
              <input type="email" class="form-control" id="bac-co-email" autocomplete="email" placeholder="name@example.com" required>
              <div class="invalid-feedback">Enter a valid email for the receipt.</div>
            </div>
            <button type="submit" class="btn btn-primary">Continue</button>
          </form>
        </div>
      </div>
    </div>
    <div class="accordion-item">
      <h3 class="accordion-header">
        <button class="accordion-button collapsed" type="button" id="bac-co-ship-btn" data-bs-toggle="collapse" data-bs-target="#bac-co-ship" aria-expanded="false" aria-controls="bac-co-ship">Delivery</button>
      </h3>
      <div id="bac-co-ship" class="accordion-collapse collapse" data-bs-parent="#bac-co">
        <div class="accordion-body">
          <fieldset>
            <legend class="form-label fs-6">Delivery speed</legend>
            <div class="form-check">
              <input class="form-check-input" type="radio" name="bac-co-speed" id="bac-co-std" checked>
              <label class="form-check-label" for="bac-co-std">Standard, 3 to 5 days, free</label>
            </div>
            <div class="form-check">
              <input class="form-check-input" type="radio" name="bac-co-speed" id="bac-co-exp">
              <label class="form-check-label" for="bac-co-exp">Express, next day, $12</label>
            </div>
          </fieldset>
        </div>
      </div>
    </div>
  </div>
  <p class="small text-danger-emphasis mt-2 mb-0 d-none" id="bac-co-msg" role="status">Finish the contact details first.</p>
</div>

What is the Bootstrap accordion?

Each panel is a header with a block of content under it, and clicking the header expands or collapses that block. It ships with Bootstrap as one of the framework’s ready-made components, and all of its behavior comes from the Collapse plugin. The Bootstrap 5.3 documentation frames it as a vertical accordion layer on top of that plugin.

The .collapse class hides a panel and .collapse.show displays it. A third class, .collapsing, sits on the panel only while the height transition runs. On a click, the plugin animates the height between 0 and the full size and flips aria-expanded on the trigger.

The animation follows the prefers-reduced-motion media query, so visitors who set that preference in their system don’t get it.

It isn’t a tab set, though people mix the two up. Tabs built with Bootstrap’s tab component always keep one pane active, while an accordion can sit with every panel closed.

Everything here reflects Bootstrap 5.3.8, the latest stable release as of October 2026. Bootstrap 6 entered alpha on October 8, 2026 and builds its accordion on native details and summary elements, so it isn’t covered.

How to build a Bootstrap accordion

The page needs Bootstrap’s CSS and JavaScript bundle first. After that it’s five nested classes per item, plus matching ids between each button and its panel.

Files to load

The stylesheet goes in the head and the script goes before the closing body tag. The Bootstrap 5.3 docs give jsDelivr links for both, and the bootstrap package installs from npm if you build with a bundler.

bootstrap.bundle.min.js includes Popper. bootstrap.min.js alone also works, since the accordion doesn’t use Popper. Whichever you pick, update the integrity hash whenever the version changes.

Because the accordion is plain HTML plus data attributes, no initialization script is needed.

Accordion markup

  1. Wrap the panels in a div with the class accordion and a unique id, such as accordionExample.
  2. Add one div with the class accordion-item for each panel.
  3. Inside it, place an h2 with the class accordion-header that wraps a button with the class accordion-button, type=”button”, data-bs-toggle=”collapse” and a data-bs-target pointing at the panel id.
  4. Add a div with the classes accordion-collapse and collapse, carrying that same id.
  5. Put the content in a div with the class accordion-body inside the panel.
<div class="accordion" id="accordionExample">
  <div class="accordion-item">
    <h2 class="accordion-header">
      <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="false" aria-controls="collapseOne">
        Item one
        </button>
    </h2>
    <div id="collapseOne" class="accordion-collapse collapse" data-bs-parent="#accordionExample">
      <div class="accordion-body">Panel content.</div>
    </div>
  </div>
</div>

Repeat the accordion-item block for every extra panel, with a new id each time.

How the ids connect

One mismatched id breaks an item, and nothing on the page tells you why.

data-bs-target holds a CSS selector, usually #collapseOne. aria-controls repeats the panel id without the hash, and the id itself has to be unique on the page. Bootstrap looks elements up with querySelector, so ids containing special characters need escaping (Bootstrap 5.3 documentation).

The example wraps each button in an h2. Change the tag to whatever level fits your page outline, since the classes handle the styling, not the element.

Open state: one panel, many panels, or open by default

Whether panels open one at a time or independently comes down to data-bs-parent. The show class and the button’s aria-expanded value decide what is open on load.

Setupdata-bs-parentStarting markupBehavior
Single openOn every .accordion-collapse.show on one panelOpening a panel closes the open one
Always openOmitted everywhere.show on any number of panelsPanels open and close independently
All closedEitherNo .show, .collapsed on every buttonNothing is open on load

Keep one panel open at a time

Set data-bs-parent="#accordionExample" on every .accordion-collapse element, using the id of the .accordion container. The Collapse docs place the attribute on the collapsible area, never on the button.

Clicking the header of the open panel still closes it. So this setup caps the accordion at one open panel but doesn’t guarantee one is always visible.

Always-open accordion

Remove data-bs-parent from every .accordion-collapse. That’s the entire change.

Panels then behave independently, which suits FAQ lists where visitors compare two or three answers side by side.

Open a panel by default

Add show to the accordion-collapse element. On the button, remove collapsed and set aria-expanded=”true”.

Skip any of those and either the chevron or the announced state is wrong until the first click.

Controlling the Bootstrap accordion with JavaScript

The accordion opens and closes without any custom script, so code only becomes necessary when you want to drive panels programmatically or react to state changes. The Collapse class behind it exposes 6 methods, 2 options and 4 events (Bootstrap 5.3 documentation).

It all runs on vanilla JavaScript, because Bootstrap 5 dropped the jQuery dependency (Bootstrap migration guide).

Initialize and configure

Manual setup loops over the .collapse elements inside the accordion and creates one instance per panel.

const items = document.querySelectorAll('#accordionExample .collapse')
items.forEach(el => new bootstrap.Collapse(el, { toggle: false }))

The toggle option defaults to true and toggles the panel on invocation, so creating instances in a loop flips each panel unless you pass toggle: false. The snippet in the accordion docs leaves that option out.

The other option is parent, which takes a selector or DOM element and defaults to null. When a panel opens, any sibling panels under that parent close. toggle is a plain boolean.

Methods and the transition rule

Use show, hide and toggle to open and close panels, and getOrCreateInstance to fetch an instance without checking whether one exists. All of them belong to Bootstrap’s programmatic API and return before the transition ends.

A call on a panel that is still animating is ignored. Wait for the shown or hidden event before chaining the next action.

Here’s how to collapse every open panel:

document.querySelectorAll('#accordionExample .collapse.show').forEach(el => {
  bootstrap.Collapse.getOrCreateInstance(el, { toggle: false }).hide()
})

Events

show.bs.collapse fires as soon as show is called, and shown.bs.collapse fires after the transition finishes. The hide side works the same way. hide.bs.collapse fires on the call, and hidden.bs.collapse fires once the panel is fully hidden.

Attach listeners to the .accordion-collapse element, not to the button.

The show and hide events accept preventDefault(), so a handler can veto opening a panel.

There’s one trap. When jQuery is on the page and body has no data-bs-no-jquery attribute, Bootstrap emits its events through jQuery’s event system. The docs then tell developers to listen with .on or .one instead of addEventListener.

Styling the Bootstrap accordion: flush variant, CSS variables and Sass

Styling happens in layers. Sass variables set the build-time defaults, and CSS variables on .accordion override them at runtime. On top of both there’s .accordion-flush for an edge-to-edge layout.

Component CSS variables arrived in Bootstrap 5.2.0 (Bootstrap blog, July 19, 2022). The 5.3.8 docs list 21 of them for the accordion.

Flush variant

Add .accordion-flush to the .accordion container. It strips some borders and rounded corners so the accordion sits edge to edge inside its parent.

It works well inside a card, a sidebar or any bordered wrapper. On a bare page background a flush accordion looks unfinished, at least to me.

CSS variables

–bs-accordion-bg sets the panel background, –bs-accordion-active-bg sets the background of the open button, and –bs-accordion-active-color sets its text color. The focus ring comes from –bs-accordion-btn-focus-box-shadow.

.accordion-brand {
  --bs-accordion-active-bg: #fff3cd;
  --bs-accordion-active-color: #664d03;
}

The variables are declared on .accordion, so a rule in a stylesheet loaded after Bootstrap’s CSS wins. That’s the standard route for overriding Bootstrap’s default styles without touching the source.

Sass variables

Sass sets the defaults the CSS variables inherit. Most spacing changes come down to $accordion-padding-y (1rem), $accordion-padding-x (1.25rem) and $accordion-icon-width (1.25rem).

Overrides go after @import “functions” and before @import “variables”, because a default cannot be changed once it has been used (Bootstrap 5.2.0 migration notes).

Chevron icon and animation speed

The chevron is an SVG data URI assigned through $accordion-button-icon and exposed as –bs-accordion-btn-icon and –bs-accordion-btn-active-icon. Open panels rotate it by -180 degrees with a .2s transform transition.

To swap in a plus and minus pair, set both icon variables and set –bs-accordion-btn-icon-transform to none, or the new icon rotates too. The icons that ship with Bootstrap work as a source for the SVG files.

The panel height animation is separate. It comes from $transition-collapse, which defaults to height .35s ease and is shared by the Collapse plugin and the accordion, so changing it affects both (Bootstrap 5.3 documentation).

Padding cannot go on a .collapse element because it breaks the height animation. Put it on .accordion-body instead.

Is the Bootstrap accordion accessible?

Mostly, yes. The default markup follows the structure of the W3C ARIA Authoring Practices Guide accordion pattern, and keyboard support comes from a native button. What’s left is a few optional pieces, plus whatever your own content and colors add.

What Bootstrap handles

Each header is a heading wrapping a single button, which is the arrangement the guide asks for. Enter and Space toggle a panel, and Tab and Shift+Tab move between headers.

The header button also carries the ARIA states the guide requires, aria-expanded for visibility and aria-controls for the panel id.

One optional piece is missing from the 5.3 example, role=”region” with aria-labelledby on each panel. The guide advises against region roles in an accordion with more than approximately 6 panels that can be expanded at the same time (W3C, ARIA Authoring Practices Guide).

The Bootstrap 4.6 docs example puts aria-labelledby on every panel, while the 5.3 example leaves it out. Tutorials that include it follow the older pattern, and the guide treats the attribute as optional.

Colors are on you. Bootstrap’s accessibility docs warn that some default palette combinations fall below the WCAG 2.2 minimum of 4.5:1, so check the contrast between text and background for any active-state colors you set.

Closing the keyboard gap

The current ARIA Authoring Practices Guide accordion page lists Enter or Space, Tab and Shift+Tab as its keyboard interactions, and a native button already covers all of them.

Bootstrap’s Collapse docs still say the implementation skips the guide’s optional keyboard interactions, a note the 4.6 docs carry in slightly different words.

Read together, the two sources say arrow-key movement between headers is a nicety, not a failure of the pattern. Add it when an accordion has many items.

document.querySelectorAll('.accordion').forEach(accordion => {
  accordion.addEventListener('keydown', event => {
    const buttons = [...accordion.querySelectorAll('.accordion-button')]
    const index = buttons.indexOf(document.activeElement)
    if (index === -1) return

    const moves = { ArrowDown: index + 1, ArrowUp: index - 1, Home: 0, End: buttons.length - 1 }
    if (!(event.key in moves)) return
    event.preventDefault()
    buttons[(moves[event.key] + buttons.length) % buttons.length].focus()
  })
})

Nested accordions need a narrower selector, otherwise inner headers join the outer list.

Bootstrap 4 vs Bootstrap 5 accordion

In Bootstrap 4 the accordion is built from cards and driven by jQuery. Bootstrap 5 gives you a dedicated .accordion component with data-bs-* attributes, and the migration guide lists it as a v5.0.0 change that replaces the card-based version.

AspectBootstrap 4.6Bootstrap 5.3
Panel markup.card with .card-header and .card-body.accordion-item with .accordion-header and .accordion-body
Triggerbutton.btn-link with data-toggle and data-targetbutton.accordion-button with data-bs-toggle and data-bs-target
Groupingdata-parentdata-bs-parent
Plugin call$(‘.collapse’).collapse()new bootstrap.Collapse(el)

The four collapse event names carried over unchanged, so only the way you subscribe to them differs.

When migrating, the attribute renames are simple:

  • data-toggle becomes data-bs-toggle
  • data-target becomes data-bs-target
  • data-parent becomes data-bs-parent

The migration guide describes the change as namespacing every plugin’s data attributes under data-bs-. The card classes have no automatic replacement, so the panel markup gets rewritten by hand.

Mixed attributes break the accordion in both directions. A Liferay DXP 7.3 forum thread had Bootstrap 5 attributes on a page running an older Bootstrap, and Liferay’s own support notes say its DXP 7.4 platform supports Bootstrap 4, where data-bs-toggle and data-bs-target do nothing.

A Wappler community thread shows the reverse. A project switched to Bootstrap 5 while a trigger still carried data-target next to data-bs-toggle, and the accordion cards would not expand.

The docs disagree with themselves on one point. Both the 4.6 and 5.3 Collapse option tables tie the parent option to the card class, yet the 5.3 accordion example groups .accordion-item panels with data-bs-parent and no card. Follow the example markup, not the option description.

Bootstrap 4 has reached end of life according to the banner on its own 4.6 docs, so a new accordion belongs on Bootstrap 5. Keep the card markup only where the rest of the site still runs 4.6.

Why is the Bootstrap accordion not working?

Most failures come from mismatched attribute prefixes, a missing data-bs-parent target, nested groups, framework conflicts, or content clipped during the animation.

SymptomCauseFix
Nothing toggles, no errordata-toggle on Bootstrap 5, or data-bs-toggle on Bootstrap 4Match every attribute to the loaded version
TypeError about querySelectorAll of null (Bootstrap 4.x)data-parent points to an id missing from the DOM, or util.js is not loaded before collapse.js in a custom buildPoint to an existing id, or include util.js first
Nested panels do not close each otherInner group sits inside an outer panel that has .collapse (a 5.1.0 and 5.1.1 regression)Update to 5.1.2 or later, or close siblings in a show.bs.collapse handler
Stuck or inconsistent panels in React, Vue or AngularBootstrap JavaScript and the framework both mutate the same DOM elementsUse a framework package such as React Bootstrap or ng-bootstrap
Content looks clipped mid-animationThe transition limits overflow while .collapsing is appliedJudge the layout after shown.bs.collapse fires

The two Bootstrap 4 causes come from twbs/bootstrap issue 26891, where a maintainer traced the error to a missing parent id and another commenter fixed it by loading util.js first. The framework row comes straight from the Bootstrap 5.3 JavaScript docs, which recommend framework-specific packages instead of Bootstrap’s own scripts.

How to nest an accordion without breaking grouping

Place the inner accordion inside an .accordion-body, since the docs allow almost any HTML there. Give the inner container its own id and point the inner panels’ data-bs-parent at it.

Issue 34850 in the twbs/bootstrap repository reported that on Bootstrap 5.1 the inner panels stopped closing each other when the outer panel carried the .collapse class. One reporter’s demo showed the same markup grouping correctly on 4.6.

The cause was a selector missing :scope, and the fix (pull request 34951) shipped in Bootstrap 5.1.2 in October 2021, so nested groups work with plain data-bs-parent on 5.3.8. Only a site stuck on 5.1.0 or 5.1.1 needs a handler that skips data-bs-parent on the inner panels:

document.querySelectorAll('#innerAccordion .collapse').forEach(panel => {
  panel.addEventListener('show.bs.collapse', event => {
    event.stopPropagation()
    document.querySelectorAll('#innerAccordion .collapse.show').forEach(open => {
      if (open !== panel) {
        bootstrap.Collapse.getOrCreateInstance(open, { toggle: false }).hide()
      }
    })
  })
})

Events bubble, which is why stopPropagation sits in the handler. A commenter on the same thread hit the reverse symptom on 5.0.1, where clicks inside an accordion closed the hamburger menu around it until they stopped the propagation.

Bootstrap accordion or the native details element?

If the page already loads Bootstrap’s JavaScript and you need Collapse events or code-driven control, the Bootstrap accordion makes sense. Otherwise details and summary is enough, because the browser handles the toggling with no script.

The Bootstrap version earns its place when you need show, hide, shown or hidden events, when panels open or close from code, or when the styling has to match the rest of a Bootstrap site.

Details and summary fits when the page doesn’t load Bootstrap JavaScript, or when content must stay readable with scripts disabled. It also works if one open panel at a time is all the grouping you need and a single toggle event is enough.

Bootstrap’s docs state that its plugins have no special fallback when JavaScript is disabled, and panels without the show class stay hidden through CSS. A details element opens and closes without any script.

Exclusive grouping needs only a shared name attribute on each details element. MDN lists the element as available across browsers since January 2020, and the name attribute reached Baseline Newly available on September 3, 2024 (Chrome 120 and Safari 17.2 in December 2023, Firefox 130 in September 2024, per Web Platform DX feature data).

Animation used to be the argument for the Bootstrap accordion. MDN now documents the ::details-content pseudo-element for animating the open and close transition, which narrows that gap.

Sources split on single-open behavior. The ARIA Authoring Practices Guide describes implementations that allow only one expanded panel, while Builder.io’s guide to animated CSS accordions warns that exclusive accordions carry accessibility and UX tradeoffs.

The data-bs-parent setup and the name attribute share that tradeoff, so the choice between them does not settle it.

Neither option fits content visitors need on every visit. Hiding answers behind clicks costs usability for anyone who needs every answer, so keep that content visible.

Bootstrap accordion FAQ

How do I open a specific item from the URL hash?

Bootstrap has no built-in hash handling, so a short script does it. On page load, read location.hash, find the matching .accordion-collapse element, and call getOrCreateInstance(element, { toggle: false }).show().

Give each panel an id that matches the hash you link to.

Can the trigger be a link instead of a button?

Yes. Use an a element with data-bs-toggle=”collapse”, an href pointing at the panel id, and role=”button”.

Bootstrap’s Collapse docs still recommend a button for semantic reasons.

What can go inside an accordion body?

Nearly any HTML. Bootstrap’s docs say the body accepts just about any markup, so images, tables and forms all fit.

The one stated limit is that the height transition restricts overflow while it runs.

Is there a clean way to add an icon beside the header text?

Yes. Put the icon element inside the accordion-button, before the label, and add a margin utility such as me-2 for spacing.

Inside the button, the icon also counts as part of the click target.

Does the accordion work with panels added after page load?

Yes, for markup that uses data attributes. Bootstrap listens for clicks at the document level, so panels inserted later respond to their triggers.

Instances created by hand with new bootstrap.Collapse need the elements to exist first.

Testing a Bootstrap accordion before launch

Start with the attribute prefix and check it against the Bootstrap version that’s actually loaded. Then tab through every header and press Enter and Space on each one. Nested groups come last, tested on the exact version you ship.

The order follows blast radius. A wrong prefix disables every panel at once, a keyboard fault affects one input method, and nested grouping touches only pages that nest.

Verified against the 5.3.8 docs in October 2026, this sequence holds. The nested grouping bug was fixed in 5.1.2, so the last check matters most on sites that still run an older 5.1 release.

The cost is one manual pass per accordion, and a page-wide accessibility checklist covers the content around it.