Customize
Learn how Bootstrap's colors power our design system theme. Customize and extend Bootstrap with Sass, a boatload of global options, and plenty of global and component-specific CSS variables.
Overview
There are multiple ways to customize Bootstrap. Your best path can depend on your project, the complexity of your build tools, the version of Bootstrap you’re using, browser support, and more.
Our two preferred methods are:
- Using Bootstrap via package manager so you can use and extend our source files.
- Using Bootstrap’s compiled distribution files or jsDelivr so you can add onto or override Bootstrap’s styles.
While we cannot go into details here on how to use every package manager, we can give some guidance on using Bootstrap with your own Sass compiler.
For those who want to use the distribution files, review the getting started page for how to include those files and an example HTML page. From there, consult the docs for the layout, components, and behaviors you’d like to use.
As you familiarize yourself with Bootstrap, continue exploring this section for more details on how to utilize our global options, making use of and changing our color system, how we build our components, how to use our growing list of CSS custom properties, and how to optimize your code when building with Bootstrap.
Sass vs CSS
When Bootstrap 5 first introduced CSS variables, the Sass vs CSS variables setup was a little confusing and somewhat limited. As such, the relationship between Sass and CSS variables was very unclear. In Bootstrap 6, we've clarified that—here's how the two interact.
- At a high level, Sass is a way to manage global configuration options and generate CSS for our utilities, components, typography, custom properties (aka CSS variables) and more.
- We consider CSS variables to be the first-class customization layer for our users.
- Sass variables are available for nearly every component—like the new
$check-*variables for checkboxes. These Sass variables are then consumed by CSS variables on the relevant selector (e.g.,.checkwith--bs-check-bg: #{$check-bg}) and applied through various properties. - CSS variables get their values from Sass variables, or CSS variables, depending on the context.
- Sass helps us generate CSS variables, too. Think theme and config values, but across components, Sass is consuming CSS variables. This gives you two, clearer avenues for customization.
With that in mind, you can customize Bootstrap 6 via CSS or Sass, both of which are easier than ever thanks to a revamped color system and theme configuration.
CSPs and embedded SVGs
Several Bootstrap components include embedded SVGs in our CSS to style components consistently and easily across browsers and devices. For organizations with more strict CSP configurations, we’ve documented all instances of our embedded SVGs (all of which are applied via background-image) so you can more thoroughly review your options.
- Accordion
- Carousel controls
- Close button (used in alerts and modals)
- Form validation icons
- Navbar toggle buttons
Based on community conversation, some options for addressing this in your own codebase include replacing the URLs with locally hosted assets, removing the images and using inline images (not possible in all components), and modifying your CSP. Our recommendation is to carefully review your own security policies and decide on the best path forward, if necessary.