Bootstrap / Bootstrap Themes and Customization
Customizing Bootstrap with SASS
This tutorial covers the process of customizing Bootstrap using SASS. You'll learn how to use SASS features to make your CSS more efficient and maintainable.
Section overview
5 resourcesExplores how to customize Bootstrap and create custom themes.
Customizing Bootstrap with SASS
Introduction
This tutorial aims to guide you through the process of customizing Bootstrap using SASS. By the end of this tutorial, you'll understand how to use SASS to make your CSS more efficient and maintainable. You’ll also learn how to apply SASS features to Bootstrap to customize it according to your needs.
What You Will Learn
- Introduction to Bootstrap and SASS
- Installing Bootstrap and setting up SASS
- Customizing Bootstrap with SASS
Prerequisites
- Basic understanding of HTML, CSS, and JavaScript
- Basic knowledge of Bootstrap and SASS
- Node.js and npm installed on your machine
Step-by-Step Guide
Installing Bootstrap and Setting up SASS
First, install Bootstrap in your project directory using npm:
npm install bootstrap
Then, install Dart Sass, which is the primary Sass compiler:
npm install sass
Customizing Bootstrap with SASS
Bootstrap's source Sass files are included if you downloaded or installed bootstrap via npm. You can import them into your project's Sass files and override the variables to customize the styles.
@import "node_modules/bootstrap/scss/bootstrap";
// You can override variable here
$theme-colors: (
"primary": #007bff,
"secondary": #6c757d,
"success": #28a745,
"info": #17a2b8,
"warning": #ffc107,
"danger": #dc3545,
"light": #f8f9fa,
"dark": #343a40
);
Code Examples
Example 1: Changing Primary Color
The following example demonstrates how to change the primary color in Bootstrap:
// Import Bootstrap
@import "node_modules/bootstrap/scss/bootstrap";
// Override the primary color
$theme-colors: (
"primary": #ff0000
);
// Re-compile Bootstrap
@import "node_modules/bootstrap/scss/bootstrap.scss";
In this code:
- We import Bootstrap's source Sass files.
- We override the primary color in the $theme-colors map.
- We re-compile Bootstrap.
Example 2: Changing the Font Size Base
The following example shows how to change the base font size:
// Import Bootstrap
@import "node_modules/bootstrap/scss/bootstrap";
// Override the base font size
$font-size-base: 1rem; // 1rem equals 16px
// Re-compile Bootstrap
@import "node_modules/bootstrap/scss/bootstrap.scss";
In this code:
- We import Bootstrap's source Sass files.
- We override the base font size with $font-size-base.
- We re-compile Bootstrap.
Summary
In this tutorial, we learned how to customize Bootstrap using SASS. We installed Bootstrap and Dart Sass, then we changed the primary color and the base font size.
Next Steps
- Explore more Bootstrap variables to customize
- Learn more about SASS and its features
Additional Resources
Practice Exercises
Exercise 1: Change the Background Color
Change the background color of the body in Bootstrap. Hint: Use the $body-bg variable.
Exercise 2: Change the Grid Breakpoints
Customize the grid breakpoints in Bootstrap. Hint: Use the $grid-breakpoints and $container-max-widths maps.
Exercise 3: Customize the Button
Customize the primary button's padding and font size. Hint: Use the $btn-padding-y, $btn-padding-x, and $btn-font-size variables.
Solutions:
// Exercise 1
$body-bg: #f0f8ff;
// Exercise 2
$grid-breakpoints: (
xs: 0,
sm: 576px,
md: 768px,
lg: 992px,
xl: 1200px,
xxl: 1400px,
);
$container-max-widths: (
sm: 540px,
md: 720px,
lg: 960px,
xl: 1140px,
xxl: 1320px,
);
// Exercise 3
$btn-padding-y: 0.5rem;
$btn-padding-x: 1.5rem;
$btn-font-size: 1.25rem;
Remember to always re-compile Bootstrap after changing the variables:
@import "node_modules/bootstrap/scss/bootstrap.scss";
Need Help Implementing This?
We build custom systems, plugins, and scalable infrastructure.
Related topics
Keep learning with adjacent tracks.
Popular tools
Helpful utilities for quick tasks.
Latest articles
Fresh insights from the CodiWiki team.
AI in Drug Discovery: Accelerating Medical Breakthroughs
In the rapidly evolving landscape of healthcare and pharmaceuticals, Artificial Intelligence (AI) in drug dis…
Read articleAI in Retail: Personalized Shopping and Inventory Management
In the rapidly evolving retail landscape, the integration of Artificial Intelligence (AI) is revolutionizing …
Read articleAI in Public Safety: Predictive Policing and Crime Prevention
In the realm of public safety, the integration of Artificial Intelligence (AI) stands as a beacon of innovati…
Read articleAI in Mental Health: Assisting with Therapy and Diagnostics
In the realm of mental health, the integration of Artificial Intelligence (AI) stands as a beacon of hope and…
Read articleAI in Legal Compliance: Ensuring Regulatory Adherence
In an era where technology continually reshapes the boundaries of industries, Artificial Intelligence (AI) in…
Read article