Close button
A generic close button for dismissing content like modals and alerts.
components
Example
Provide an option to dismiss or close a component with .btn-close. The icon is rendered with a CSS mask-image, so it inherits the color from the .btn-close class—no inline SVG required. Be sure to include text for screen readers, as we’ve done with the .visually-hidden “Close” text. Real text inside the button also keeps it usable when the CSS does not load.
<button type="button" class="btn-close"><span class="visually-hidden">Close</span></button>
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.
<button type="button" class="btn-close" disabled><span class="visually-hidden">Close</span></button>
Dark variant
Add data-bs-theme="dark" to the .btn-close, or to its parent element, to invert the close button. This happens automatically when in dark mode.
<div data-bs-theme="dark">
<button type="button" class="btn-close"><span class="visually-hidden">Close</span></button>
<button type="button" class="btn-close" disabled><span class="visually-hidden">Close</span></button>
</div>
CSS
Variables
Close button use local CSS variables on .btn-close for real-time customization. Values for the CSS variables
are generated from Sass maps unique to each component and applied to the aforementioned class.
// stylelint-disable-next-line scss/dollar-variable-default
$btn-close-tokens: defaults(
(
--btn-close-size: 1em,
--btn-close-padding: .25em,
--btn-close-color: var(--fg-body),
--btn-close-icon: #{escape-svg(url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path d='M.293.293a1 1 0 0 1 1.414 0L8 6.586 14.293.293a1 1 0 1 1 1.414 1.414L9.414 8l6.293 6.293a1 1 0 0 1-1.414 1.414L8 9.414l-6.293 6.293a1 1 0 0 1-1.414-1.414L6.586 8 .293 1.707a1 1 0 0 1 0-1.414'/></svg>"))},
--btn-close-opacity: .6,
--btn-close-hover-opacity: .8,
--btn-close-focus-opacity: 1,
--btn-close-disabled-opacity: .25,
),
$btn-close-tokens
);