Skip to main content

Close button

A generic close button for dialogs, alerts and more.

Bootstrap’s close button docs describe the markup and CSS.

Example

The directive adds .btn-close, sets type="button" and gives the button a default aria-label of “Close”. The icon is drawn with a CSS mask, so it follows the button’s color.

HTML
<button bsCloseButton></button>

Disabled state

Add disabled to fade the button and stop hover and active styles.

HTML
<button bsCloseButton disabled></button>

Dark variant

Add data-bs-theme="dark" to the button or a parent to invert it. This happens on its own in dark mode.

HTML
<div data-bs-theme="dark" class="d-flex gap-2 p-3 bg-body rounded">
  <button bsCloseButton></button>
  <button bsCloseButton disabled></button>
</div>

Accessible label

A screen reader only announces the label, so say what the button closes when “Close” isn’t clear enough, for example when a page has several close buttons.

HTML
<div class="d-flex gap-2">
  <button bsCloseButton aria-label="Dismiss notification"></button>
  <button bsCloseButton aria-label="Remove filter: In stock"></button>
</div>

Default label

Change the default label for the whole app, or for part of it, with provideBsCloseButtonConfig(), for example to translate it or, as here, to use “Dismiss”. A label set on a button still wins.

<button bsCloseButton></button>

Dismissing content

Bind (click) to hide your own content. Components that close themselves have their own: dismissible on alerts, and bsDialogClose, bsDrawerClose and bsToastClose on a close button inside dialogs, drawers and toasts.

Your changes were saved.

@if (visible()) {
  <div class="d-flex align-items-center gap-3 p-3 border rounded">
    <p class="mb-0 me-auto">Your changes were saved.</p>
    <button bsCloseButton aria-label="Dismiss message" (click)="visible.set(false)"></button>
  </div>
} @else {
  <button type="button" bsButton="outline" theme="primary" (click)="visible.set(true)">
    Show message
  </button>
}

API

BsCloseButton

Selector: button[bsCloseButton]

Inputs

NameTypeDefaultDescription
aria-labelstring'Close'Accessible label of the button.