In this tutorial, our goal is to learn how to create and apply custom themes in Bootstrap. You will learn how to create a consistent look and feel across your entire project by customizing Bootstrap's default aesthetics to match your needs.
By the end of this tutorial, you will be able to:
- Create your own custom Bootstrap theme
- Apply the custom theme to your website
Bootstrap is a powerful and popular CSS framework. It becomes even more powerful when you can customize it to suit your style and branding. Let's dive into the steps:
You can download the Bootstrap source files from the official website. Unzip the downloaded file and you will find a scss
directory which contains all the SASS source files.
The main power of Bootstrap customization lies in its use of SASS variables. Open the _variables.scss
file. This file contains pre-set variables that define the look and feel of Bootstrap.
To create a custom theme, you need to override these variables with your own values. It's best practice not to change the _variables.scss
file directly, but rather create your own file (e.g., _custom.scss
) and override the variables there.
After you've made your customizations, you will need to recompile the Bootstrap CSS. You can do this using a SASS compiler. There are many SASS compilers available, one of the most popular ones is Node-sass.
Below are some practical examples of how to customize Bootstrap themes.
First, let's change the primary color. In your _custom.scss
file, override the primary color variable:
$primary: #ff6347; // Set primary color to tomato
You can also easily change the font of your theme. Let's say we want to use the 'Roboto' font:
$font-family-sans-serif: 'Roboto', sans-serif; // Set font to Roboto
After doing your changes, compile your CSS using your SASS compiler. The result would be a new compiled bootstrap.css
file that you can link in your HTML files.
In this tutorial, we learned how to create and apply custom themes in Bootstrap. We learned how to override Bootstrap's default variables to match our own style and branding.
Next, you could learn more about other SASS features, like mixins and functions, which can help you create more advanced themes. You might also want to look into how to automate the SASS compilation process using task runners like Grunt or Gulp.
btn-success
class._custom.scss
file, you can override the success color and the button text color:$success: #5cb85c;
$btn-success-color: #fff;
@include button-variant(#f8f9fa, #5cb85c, #28a745);
.card-custom {
padding: 1.5rem;
border-radius: 1rem;
box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
}
Then, compile your SASS to CSS, and you can use these classes in your HTML.