Loading...
Skip to main content

Close button

A generic close button for dismissing content like modals and alerts.

CloseButton supplies the close-button styles, a default type="button", and the accessible label “Close”. Pass an onClick handler when wiring it to your own dismissible content.

Example

Use CloseButton to dismiss or close a component. Its icon is rendered with a CSS mask and inherits its color—no inline SVG is required. Set an accessible label with aria-label so screen readers can identify the button.

<div className="d-flex flex-wrap gap-2 align-items-center">
<CloseButton aria-label="Close" />
</div>

Disabled state

Disabled close buttons change their opacity. We’ve also applied pointer-events: none and user-select: none to preventing hover and active states from triggering.

<div className="d-flex flex-wrap gap-2 align-items-center">
<CloseButton
aria-label="Close"
disabled
/>
</div>

Dark variant

Set data-bs-theme="dark" on CloseButton or one of its parent elements to invert it. This happens automatically in dark mode.

<div className="bg-inverse">
<div data-bs-theme="dark">
<CloseButton aria-label="Close" />
<CloseButton
aria-label="Close"
disabled
/>
</div>
</div>

CSS

Variables

Customize the component with the following local CSS variables. Override them through the wrapper’s style prop or your own CSS module.

CSS variableDefault
--bs-btn-close-size1.25rem
--bs-btn-close-colorinherit
--bs-btn-close-iconSVG mask image
--bs-btn-close-opacity0.5
--bs-btn-close-hover-opacity0.75
--bs-btn-close-focus-opacity0.85
--bs-btn-close-disabled-opacity0.25
Documentation navigation
On this page
On this page