Customize Bootstrap
Bootstrap is designed to be customized rather than used as-is on every project. This lesson introduces the main customization strategies you'll build on in later lessons.
Customize Bootstrap Overview
There are three main levels of Bootstrap customization: overriding Sass variables before compiling (the most powerful and thorough approach), overriding the runtime CSS custom properties Bootstrap 5.3+ exposes on many components, and adding your own CSS on top of the compiled framework for one-off tweaks.
Choosing the right level depends on scope: Sass variables are ideal for site-wide theme changes like colors and fonts, CSS variables are great for quick runtime or per-component overrides, and plain custom CSS suits small, isolated adjustments that don't need to propagate everywhere.
| Concept | Description | Common Usage |
| Sass variable overrides | Set variables before @import 'bootstrap' | Site-wide color, spacing, and font changes |
| CSS custom properties | Runtime --bs-* variables on components | Quick per-component or per-page overrides |
| Custom CSS on top | Additional stylesheet loaded after Bootstrap | Small, isolated visual tweaks |
| Utility API | Sass-based system for adding new utility classes | Project-specific utilities matching Bootstrap's style |
| Theming via data attributes | data-bs-theme="dark" and similar | Switching between light/dark or custom themes |
Customize Bootstrap Example
// custom.scss — Sass variable overrides (most powerful)
$primary: #7c3aed;
$border-radius: 0.75rem;
$font-family-base: 'Inter', sans-serif;
@import 'bootstrap/scss/bootstrap';
/* Runtime CSS variable override (quick, no rebuild needed) */
.card {
--bs-card-border-radius: 1rem;
}
Overriding Sass variables like $primary before importing Bootstrap regenerates every component and utility class that references that color, giving a consistent, site-wide result. The CSS variable override below it demonstrates a lighter-weight approach: changing a single component's border radius at runtime without recompiling Sass.
Top 10 Customize Bootstrap Examples
These are the customization entry points you'll use most often when adapting Bootstrap to a brand.
| # | Example | Syntax |
| 1 | Override primary color | $primary: #7c3aed;
@import 'bootstrap/scss/bootstrap'; |
| 2 | Override border radius | $border-radius: 0.75rem; |
| 3 | Override base font | $font-family-base: 'Inter', sans-serif; |
| 4 | Runtime CSS variable override | .card { --bs-card-border-radius: 1rem; } |
| 5 | Dark theme attribute | <html data-bs-theme="dark"> |
| 6 | Custom utility via Sass map | $utilities: map-merge($utilities, ("cursor": (property: cursor, values: pointer))); |
| 7 | Importing only needed partials | @import 'bootstrap/scss/functions';
@import 'bootstrap/scss/variables'; |
| 8 | Adding a new theme color | $theme-colors: map-merge($theme-colors, ("brand": #ff6b6b)); |
| 9 | Overriding a component variable | $btn-border-radius: 2rem; |
| 10 | Custom CSS layered after Bootstrap | <link rel="stylesheet" href="bootstrap.min.css">
<link rel="stylesheet" href="custom.css"> |
Popular Real-World Customize Bootstrap Examples
These customization patterns are common when adapting Bootstrap to match a specific brand identity.
| Scenario | Pattern |
| Rebranding the primary color palette | $primary: #0f766e;
@import 'bootstrap/scss/bootstrap'; |
| Adding a custom brand theme color | $theme-colors: map-merge($theme-colors, ("brand": #ff6b6b)); |
| Switching base font for the whole site | $font-family-base: 'Poppins', sans-serif; |
| Softening all corners site-wide | $border-radius: 1rem;
$border-radius-lg: 1.25rem; |
| One-off button style tweak via CSS variable | .btn-primary { --bs-btn-bg: #4f46e5; } |
| Enabling dark mode toggle | <html data-bs-theme="dark"> |
| Adding project-specific utility classes | $utilities: map-merge($utilities, ("cursor": (property: cursor, values: pointer grab))); |
| Trimming unused components from the build | @import 'bootstrap/scss/reboot';
@import 'bootstrap/scss/grid'; |
Best Practices
- Override Sass variables before the @import 'bootstrap' line, since Bootstrap's source reads them in that order.
- Use CSS custom property overrides for quick, scoped tweaks that don't need a rebuild.
- Group all your variable overrides in one clearly labeled file for easy maintenance.
- Prefer extending $theme-colors with map-merge instead of hardcoding new one-off classes.
- Keep custom CSS layered strictly after Bootstrap's stylesheet in the load order.
- Document why each variable was overridden, especially non-obvious values like border radius or spacing scale changes.
- Test customizations across every component that references the changed variable, not just the one you were focused on.
Common Mistakes
- Placing Sass variable overrides after the @import statement, so they have no effect.
- Overriding compiled CSS classes directly instead of the underlying Sass variables, causing drift after upgrades.
- Forgetting that some component-specific variables exist separately from the global theme variables.
- Mixing too many customization approaches (Sass, CSS variables, and ad-hoc CSS) without a clear system.
- Not testing dark mode (data-bs-theme="dark") after making custom color changes.
- Upgrading Bootstrap versions without checking whether overridden variable names still exist.
Key Takeaways
- Bootstrap can be customized through Sass variables, runtime CSS variables, or layered custom CSS.
- Sass variable overrides must come before the framework's @import statement.
- CSS custom properties allow lightweight, per-component overrides without a rebuild.
- The Utility API lets you add project-specific utility classes matching Bootstrap's conventions.
- data-bs-theme provides a built-in mechanism for light/dark theme switching.
Pro Tip
Start every new Bootstrap project with a small custom.scss file that overrides just $primary, $font-family-base, and $border-radius before importing the framework—this alone makes a site feel branded rather than default Bootstrap.