Bootstrap 5 (update 2021)
The method is still the same for Bootstrap 5.
https://codeply.com/p/iauLPArGqE
Bootstrap 4
To change the primary, or any of the theme colors in Bootstrap 4 SASS, set the appropriate variables before importing bootstrap.scss
. This allows your custom scss to override the !default values…
$primary: purple;
$danger: red;
@import "bootstrap";
Demo: https://codeply.com/go/f5OmhIdre3
In some cases, you may want to set a new color from another existing Bootstrap variable. For this @import the functions and variables first so they can be referenced in the customizations…
/* import the necessary Bootstrap files */
@import "bootstrap/functions";
@import "bootstrap/variables";
$theme-colors: (
primary: $purple
);
/* finally, import Bootstrap */
@import "bootstrap";
Demo: https://codeply.com/go/lobGxGgfZE
Also see: this answer, this answer or changing the button color in (CSS or SASS)
It’s also possible to change the primary color with CSS only but it requires a lot of additional CSS since there are many -primary
variations (btn-primary, alert-primary, bg-primary, text-primary, table-primary, border-primary, etc…) and some of these classes have slight colors variations on borders, hover, and active states. Therefore, if you must use CSS it’s better to use target one component such as changing the primary button color.