Skip to content

Spinner ​

An accessible loading indicator built on Bootstrap spinners, with sizes and a muted variant.

Installation ​

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

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

Usage ​

html
<div class="spinner-border bootcn-spinner" role="status">
  <span class="visually-hidden">Loading…</span>
</div>

<!-- Next to visible text: hide the spinner, announce the text -->
<div class="d-flex align-items-center gap-2" role="status">
  <span class="spinner-border bootcn-spinner bootcn-spinner--sm" aria-hidden="true"></span>
  <span>Syncing your files…</span>
</div>

For a spinner inside a button, use the Button component's loading state.

Modifiers ​

  • bootcn-spinner--sm, bootcn-spinner--lg — sizes (1rem, 1.5rem default, 2.5rem).
  • bootcn-spinner--muted — secondary text color. Any text-* utility also works.

Sizes are set through Bootstrap's own --bs-spinner-* variables on the bootcn-spinner element only.

Dependencies ​

  • Bootstrap 5.3+ CSS.
  • themes/tokens/tokens.css.

No JavaScript.

Accessibility ​

  • Use role="status" so the loading message is announced, and always include text (visible or .visually-hidden).
  • Bootstrap slows the spin when the user prefers reduced motion; the spinner keeps moving slowly because it signals ongoing activity.

Source ​

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

html
<div class="d-flex flex-wrap align-items-center gap-4">
  <div class="spinner-border bootcn-spinner bootcn-spinner--sm" role="status">
    <span class="visually-hidden">Loading…</span>
  </div>
  <div class="spinner-border bootcn-spinner" role="status">
    <span class="visually-hidden">Loading…</span>
  </div>
  <div class="spinner-border bootcn-spinner bootcn-spinner--lg" role="status">
    <span class="visually-hidden">Loading…</span>
  </div>
  <div class="spinner-border bootcn-spinner bootcn-spinner--muted" role="status">
    <span class="visually-hidden">Loading…</span>
  </div>
</div>

<div class="d-flex align-items-center gap-2 mt-4" role="status">
  <span class="spinner-border bootcn-spinner bootcn-spinner--sm" aria-hidden="true"></span>
  <span>Syncing your files…</span>
</div>
css
.bootcn-spinner {
  --bs-spinner-width: 1.5rem;
  --bs-spinner-height: 1.5rem;
  --bs-spinner-border-width: 0.15em;

  flex-shrink: 0;
  color: var(--bootcn-primary);
}

.bootcn-spinner--sm {
  --bs-spinner-width: 1rem;
  --bs-spinner-height: 1rem;
  --bs-spinner-border-width: 0.15em;
}

.bootcn-spinner--lg {
  --bs-spinner-width: 2.5rem;
  --bs-spinner-height: 2.5rem;
}

.bootcn-spinner--muted {
  color: var(--bs-secondary-color);
}

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