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 variable | Default |
|---|---|
--bs-btn-close-size | 1.25rem |
--bs-btn-close-color | inherit |
--bs-btn-close-icon | SVG mask image |
--bs-btn-close-opacity | 0.5 |
--bs-btn-close-hover-opacity | 0.75 |
--bs-btn-close-focus-opacity | 0.85 |
--bs-btn-close-disabled-opacity | 0.25 |