Ask any question about Bootstrap here... and get an instant response.
Post this Question & Answer:
How can I customize the default spacing scale in Bootstrap 5?
Asked on Feb 03, 2026
Answer
In Bootstrap 5, you can customize the default spacing scale by modifying the Sass variables. This allows you to define your own spacing values that will be used throughout your project.
<!-- BEGIN COPY / PASTE -->
$spacers: (
0: 0,
1: 0.25rem,
2: 0.5rem,
3: 1rem,
4: 1.5rem,
5: 3rem
);
// Import Bootstrap's functions and variables
@import "node_modules/bootstrap/scss/functions";
@import "node_modules/bootstrap/scss/variables";
// Override the default spacers
@import "node_modules/bootstrap/scss/mixins";
@import "node_modules/bootstrap/scss/utilities";
<!-- END COPY / PASTE -->Additional Comment:
✅ Answered with Bootstrap 5 best practices.- To customize the spacing scale, you need to override the `$spacers` map before importing Bootstrap's utilities.
- Ensure you have a Sass compiler set up to process the SCSS files.
- The `$spacers` map uses keys for spacing levels and values for the corresponding sizes.
- After defining your custom spacers, import Bootstrap's mixins and utilities to apply the changes.
- This approach allows you to maintain consistency across your project with a customized spacing scale.
Recommended Links:
