Skip to content

Collapsible ​

A panel that shows a summary and expands to reveal more, built on Bootstrap Collapse.

  • Version 1.0.0
  • Bootstrap 5.3+
  • Requires Bootstrap CSS + Bootstrap JS bundle
  • Source on GitHub

Installation ​

bash
npx bootcn add collapsible
bash
pnpm dlx bootcn add collapsible
bash
yarn dlx bootcn add collapsible
bash
bunx --bun bootcn add collapsible

The CLI also installs the design tokens and these components: button. It prints the <link> and <script> tags to add to your layout.

Usage ​

The trigger is a button with data-bs-toggle="collapse" pointing at the .collapse element. Bootstrap animates the height and keeps aria-expanded in sync. For a list of such panels, use the Accordion component.

Accessibility ​

  • The trigger is a real button with aria-expanded and aria-controls.
  • An icon-only trigger needs visually hidden text ("Show all invoices").

Dependencies ​

  • Bootstrap 5.3+ CSS and the JS bundle.
  • themes/tokens/tokens.css.
  • The button component.

Source ​

The exact files the CLI installs (collapsible@1.0.0). View on GitHub · Report an issue

html
<div class="bootcn-collapsible">
  <div class="bootcn-collapsible__header">
    <p class="bootcn-collapsible__title">3 unpaid invoices</p>
    <button
      class="btn bootcn-button bootcn-button--ghost bootcn-button--icon bootcn-button--sm"
      type="button"
      data-bs-toggle="collapse"
      data-bs-target="#bootcn-collapsible-content"
      aria-expanded="false"
      aria-controls="bootcn-collapsible-content"
    >
      <svg
        class="bootcn-icon"
        width="16"
        height="16"
        viewBox="0 0 24 24"
        fill="none"
        stroke="currentColor"
        stroke-width="2"
        stroke-linecap="round"
        stroke-linejoin="round"
        aria-hidden="true"
        focusable="false"
      >
        <path d="m7 15 5 5 5-5" />
        <path d="m7 9 5-5 5 5" />
      </svg>
      <span class="visually-hidden">Show all invoices</span>
    </button>
  </div>
  <div class="bootcn-collapsible__item">Invoice #1042: Website redesign</div>
  <div class="collapse" id="bootcn-collapsible-content">
    <div class="bootcn-collapsible__item">Invoice #1041: Hosting, November</div>
    <div class="bootcn-collapsible__item">Invoice #1040: Support plan</div>
  </div>
</div>
css
.bootcn-collapsible {
  max-width: 24rem;
}

.bootcn-collapsible__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.bootcn-collapsible__title {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 600;
}

.bootcn-collapsible__item {
  margin-top: 0.5rem;
  padding: 0.5rem 1rem;
  border: var(--bootcn-border-width) solid var(--bootcn-border-color);
  border-radius: var(--bootcn-radius);
  font-family: var(--bs-font-monospace);
  font-size: 0.8125rem;
}

Released under the MIT License. Not affiliated with Bootstrap or shadcn/ui.