Customize Bootstrap 5 Design Tokens with Sass: A Practical Guide
Override Bootstrap's Sass variables before importing the framework to customize design tokens safely. Learn the correct import order, utility API usage, and verification steps.
22 Nov 2025, 11:26 UTC

The Problem with CSS Overrides
When you override Bootstrap's compiled CSS with custom rules, you're fighting the framework's specificity and creating maintenance debt. Your changes get buried under !important flags, and upgrading Bootstrap becomes a minefield of merge conflicts. The better path is customizing at the Sass layer—where Bootstrap generates its CSS from variables and maps.
Prerequisites
- Node.js (16+) with npm or yarn
- Dart Sass as the Sass compiler (
npx sassworks) - Bootstrap 5 installed via npm (
npm install bootstrap) - Basic familiarity with Sass syntax
The Sass Customization Workflow
Bootstrap 5 is built to be customized by overriding its Sass variables before importing the framework. Here's the critical import order:
- Import Bootstrap functions—these provide helpers like
map-get()andrgba() - Override your variables—set your custom values for
$primary,$body-bg, etc. - Import Bootstrap's variables, mixins, and functions
- Import the rest of Bootstrap
Creating Your Custom Sass Entry File
Start a new src/custom.scss file:
// 1. Import Bootstrap functions
@import "node_modules/bootstrap/scss/functions";
// 2. Override variables
$primary: #0066cc;
$secondary: #6c757d;
$body-bg: #f8f9fa;
$font-family-base: 'Inter', system-ui, sans-serif;
// Add custom theme colors to the $theme-colors map
$theme-colors: (
"primary": $primary,
"secondary": $secondary,
"success": #28a745,
"danger": #dc3545,
"warning": #ffc107,
"info": #17a2b8,
"light": #f8f9fa,
"dark": #343a40,
"brand": #6f42c1 // New custom color
);
// 3. Import Bootstrap variables
@import "node_modules/bootstrap/scss/variables";
// 4. Import Bootstrap mixins
@import "node_modules/bootstrap/scss/mixins";
// 5. Import Bootstrap utilities (optional)
@import "node_modules/bootstrap/scss/utilities";
// 6. Import components you need
@import "node_modules/bootstrap/scss/bootstrap";
Using the Utility API for Custom Utilities
Bootstrap 5's utility API lets you generate responsive and stateful utilities without writing CSS. Add this before the final Bootstrap import:
// Extend utilities with custom spacing
$utilities: (
"spacing": (
"values": (
"10": 2.5rem,
"15": 3.75rem
)
)
);
This generates classes like .p-10 and .pt-15, plus responsive variants like .p-10-md.
Selective Module Imports for Smaller Bundles
If you only need the grid and buttons, avoid importing the full Bootstrap:
// Instead of @import "bootstrap";
@import "node_modules/bootstrap/scss/grid";
@import "node_modules/bootstrap/scss/buttons";
@import "node_modules/bootstrap/scss/utilities";
Expected Checks and Verification
After compiling your Sass, verify these outputs:
- Custom colors appear—search compiled CSS for
.btn-brandor.text-brand - Responsive utilities generate correctly—confirm
.p-10-mdexists in output - File size reduction—compare your bundle against full Bootstrap build
- Visual inspection—render a test page and check colors in devtools
Common Pitfalls and Recovery
Order matters—if you import Bootstrap's variables before overriding them, your changes are ignored. The compiled CSS will show default colors, not your custom ones.
Version pinning—Bootstrap's internal map keys can change between minor versions. In package.json:
"bootstrap": "5.3.2" // Pin to exact version
Recovery from broken builds—if Sass compilation fails, check that all variable overrides happen before the variables import. Use browser devtools to inspect which CSS rules are actually applied.
Practical Example: Brand Color Integration
Adding a brand color that automatically generates button variants, text classes, and background utilities:
$theme-colors: map-merge(
$theme-colors,
("brand": #6f42c1)
);
// Now you can use:
// .btn-brand
// .text-brand
// .bg-brand
// .border-brand
This approach keeps your theme consistent across all components without writing custom CSS rules.
Limitations
Bootstrap 4 and 5 have different variable names and map structures—code won't port directly. Deep customizations may silently break on minor upgrades if internal keys change. Always review changelogs before updating.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.