Skip to content

Close button ​

An icon button that closes dialogs, sheets, alerts and banners, in three sizes.

Installation ​

bash
npx bootcn add close-button
bash
pnpm dlx bootcn add close-button
bash
yarn dlx bootcn add close-button
bash
bunx --bun bootcn add close-button

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

Usage ​

Use it in place of Bootstrap's .btn-close when you want the Bootcn look: add data-bs-dismiss="modal" (or alert, offcanvas, toast) as with any Bootstrap close button. Sizes: bootcn-close-button--sm and bootcn-close-button--lg.

Accessibility ​

  • Always give it an accessible name (aria-label="Close", or "Close dialog" when several are on the page); the icon is hidden from screen readers.
  • The hit area is at least 24 × 24 px, even in the small size.

Dependencies ​

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

Source ​

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

html
<div class="bootcn-close-button-demo">
  <button type="button" class="bootcn-close-button bootcn-close-button--sm" aria-label="Close">
    <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="M18 6 6 18" />
      <path d="m6 6 12 12" />
    </svg>
  </button>
  <button type="button" class="bootcn-close-button" aria-label="Close">
    <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="M18 6 6 18" />
      <path d="m6 6 12 12" />
    </svg>
  </button>
  <button type="button" class="bootcn-close-button bootcn-close-button--lg" aria-label="Close">
    <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="M18 6 6 18" />
      <path d="m6 6 12 12" />
    </svg>
  </button>
  <button type="button" class="bootcn-close-button" aria-label="Close" disabled>
    <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="M18 6 6 18" />
      <path d="m6 6 12 12" />
    </svg>
  </button>
</div>
css
.bootcn-close-button {
  --bootcn-close-size: 2rem;
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: var(--bootcn-close-size);
  height: var(--bootcn-close-size);
  padding: 0;
  border: 0;
  border-radius: var(--bootcn-radius);
  background: transparent;
  color: var(--bootcn-muted-foreground);
  transition:
    background-color var(--bootcn-transition),
    color var(--bootcn-transition);
}

.bootcn-close-button:hover {
  background-color: var(--bootcn-accent);
  color: var(--bootcn-foreground);
}

.bootcn-close-button:focus-visible {
  outline: 0;
  box-shadow: var(--bootcn-focus-ring);
}

.bootcn-close-button:disabled {
  opacity: 0.5;
  pointer-events: none;
}

.bootcn-close-button--sm {
  --bootcn-close-size: 1.5rem;
}

.bootcn-close-button--sm .bootcn-icon {
  width: 0.875rem;
  height: 0.875rem;
}

.bootcn-close-button--lg {
  --bootcn-close-size: 2.5rem;
}

.bootcn-close-button--lg .bootcn-icon {
  width: 1.25rem;
  height: 1.25rem;
}

/* Preview layout only. */
.bootcn-close-button-demo {
  display: flex;
  align-items: center;
  gap: 1rem;
}

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