Skip to main content

Components

Close button

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

View page source on GitHub

Example#

Provide an option to dismiss or close a component with .btn-close. The icon is drawn in currentColor, so it follows the text color of its parent. Be sure to include text for screen readers, as we’ve done with aria-label.

<button type="button" class="btn-close" aria-label="Close"></button>

Disabled state#

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

<button type="button" class="btn-close" disabled aria-label="Close"></button>

Dark variant#

Add data-bs-theme="dark" to the .btn-close, or to its parent element, to get a close button for dark surfaces.

<div data-bs-theme="dark">
  <button type="button" class="btn-close" aria-label="Close"></button>
  <button type="button" class="btn-close" disabled aria-label="Close"></button>
</div>

Bootstrap's deprecated .btn-close-white still works as well; it simply sets --felt-btn-close-color to white.

CSS#

Variables#

The close button is built on local CSS variables, like Bootstrap's: .btn-close declares them, and you can set them on any close button.

TokenDefaultBootstrap
--felt-btn-close-colorcurrentColor--bs-btn-close-color
--felt-btn-close-bgurl("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='m3.5 3.5 9 9m0-9-9 9' stroke='%23000' stroke-width='1.8' stroke-linecap='round' fill='none'/%3E%3C/svg%3E")--bs-btn-close-bg
--felt-btn-close-opacity.5--bs-btn-close-opacity
--felt-btn-close-hover-opacity.75--bs-btn-close-hover-opacity
--felt-btn-close-focus-opacity1--bs-btn-close-focus-opacity
--felt-btn-close-disabled-opacity.25--bs-btn-close-disabled-opacity

felt-css draws the X as a mask in --felt-btn-close-color (the text colour by default), so --felt-btn-close-bg gives only its shape: any image works, its colours don't count. That is also why there is no --bs-btn-close-filter counterpart: dark mode and .btn-close-white change the colour instead of filtering an image.