Bootstrap SASS variable overrides let you change Bootstrap's default styles easily. This helps you make your website look unique without rewriting all the CSS.
Bootstrap SASS variable overrides
$variable-name: new-value;
$primary: #ff5733;$font-size-base: 1.125rem;$btn-padding-y: 0.75rem; $btn-padding-x: 1.5rem;
This example shows how to override Bootstrap's primary color and base font size before importing Bootstrap's styles. Then it uses the new primary color for a heading and a custom button style that extends Bootstrap's button.
@use "sass:color"; // Override Bootstrap variables before import $primary: #0077cc; $font-size-base: 1.125rem; @import "bootstrap/scss/bootstrap"; body { font-family: Arial, sans-serif; } h1 { color: $primary; font-size: $font-size-base; } .btn-custom { @extend .btn; background-color: $primary; color: white; padding: 0.75rem 1.5rem; border-radius: 0.5rem; border: none; cursor: pointer; } .btn-custom:hover { background-color: color.scale($primary, $lightness: -10%); }
Always override variables before importing Bootstrap's SASS files to ensure your changes take effect.
Use a SASS compiler like Dart Sass to process your SASS files into CSS.
Check Bootstrap's official documentation for the full list of variables you can override.
Override Bootstrap SASS variables by setting new values before importing Bootstrap.
This lets you customize colors, fonts, spacing, and more easily.
Keep your custom styles separate to make future Bootstrap updates simple.
Practice
$primary color?Solution
Step 1: Understand Bootstrap SASS variable loading
Bootstrap uses SASS variables during compilation, so variables must be set before importing Bootstrap's SASS files to take effect.Step 2: Apply variable override before import
By setting$primarybefore the import, Bootstrap uses the new value instead of the default.Final Answer:
Set$primarybefore importing Bootstrap's SASS files -> Option AQuick Check:
Override variables before import = A [OK]
- Setting variables after importing Bootstrap
- Editing compiled CSS instead of SASS variables
- Trying to override variables in CSS files
$font-size-base to 1.25rem?Solution
Step 1: Recall SASS variable syntax
SASS variables use$variable-name: value;syntax without equals sign or !default when overriding.Step 2: Identify correct override syntax
To override, simply assign$font-size-base: 1.25rem;before importing Bootstrap.Final Answer:
$font-size-base: 1.25rem; -> Option BQuick Check:
SASS variable override syntax = D [OK]
- Using equals sign instead of colon
- Adding !default when overriding
- Omitting the $ sign before variable name
$btn-primary-bg: #ff0000; @import 'bootstrap';
Solution
Step 1: Check variable override before import
The variable$btn-primary-bgis set to red before importing Bootstrap, so Bootstrap uses this value.Step 2: Understand Bootstrap button background
Bootstrap buttons use$btn-primary-bgfor the primary button background color.Final Answer:
Red (#ff0000) -> Option DQuick Check:
Override variable before import changes button color = A [OK]
- Expecting default color despite override
- Setting variable after import
- Confusing variable names
$spacer to 3rem but your Bootstrap layout spacing did not change. What is the most likely mistake?Solution
Step 1: Check variable override timing
Setting$spacerafter importing Bootstrap has no effect because variables must be set before import.Step 2: Verify syntax and compilation
Using equals sign is invalid syntax and forgetting to recompile means changes won't apply.Step 3: Combine all errors
Any of these mistakes can cause the override to fail, so all are likely causes.Final Answer:
A, B, and D -> Option AQuick Check:
Timing, syntax, and compilation errors cause override failure = C [OK]
- Setting variables after import
- Using wrong syntax with equals sign
- Not recompiling SASS after changes
Solution
Step 1: Understand maintainability best practices
Editing Bootstrap's original files makes updates hard and error-prone.Step 2: Use separate SASS file for overrides
Setting variables in a separate file before importing Bootstrap keeps customizations clean and easy to update.Step 3: Avoid CSS or JS overrides for variables
CSS overrides can't change SASS variables, and JS changes styles after load, not at compile time.Final Answer:
Create a separate SASS file that sets$primaryand$font-size-basebefore importing Bootstrap -> Option CQuick Check:
Separate override file before import = B [OK]
- Editing Bootstrap source files directly
- Trying to override variables in CSS
- Using JavaScript for style changes instead of SASS
Ready to prove it?
Pass the test and this pattern moves unknown
