How to Edit, Customize, and Override Bootstrap CSS to Suit Your Brand
Bootstrap is a powerful and popular front-end framework that allows developers to quickly create responsive, mobile-first websites. Out of the box, Bootstrap provides a professional, polished look-and-feel that works well for many projects. But what if you want to customize that default look-and-feel extensively to match your own site or brand?
Fortunately, Bootstrap is designed to be highly customizable. With the right approach, it‘s possible to completely override Bootstrap‘s default styles and craft a unique design while still harnessing the power of the framework. In this post, we‘ll take a deep dive into two methods for customizing Bootstrap: using CSS overrides and using Sass variables. By the end, you‘ll be able to adapt Bootstrap to suit your own designs and truly make it your own.
Method 1: Using CSS Overrides
The simplest way to customize Bootstrap is to use CSS overrides. With this method, you leave Bootstrap‘s core CSS file untouched and simply add your own custom styles afterwards to override Bootstrap‘s default styling. Because CSS cascades down, with later styles overriding earlier ones, this allows you to surgically change only the styles you want.
To demonstrate, consider Bootstrap‘s default button styling:

Let‘s say you want to change the default blue color to a different brand color. Instead of messing with Bootstrap directly, you‘d simply add the following CSS to your own stylesheet:
.btn-primary {
background-color: #a71e7c;
border-color: #a71e7c;
}
.btn-primary:hover {
background-color: #9a0b6b;
border-color: #9a0b6b;
}
Here‘s the result:

As you can see, the default blue has been replaced with a lovely shade of purple, while still retaining the default CSS transitions, borders, etc.
Using your browser‘s developer tools, you can inspect any element on a Bootstrap site and see what styles are being applied where. This lets you surgically override only the styles you want to change.

Customizing Bootstrap‘s Global Styles
In addition to overriding styles on a per-element basis, you can also customize Bootstrap‘s global base styles. For example, to change Bootstrap‘s default sans-serif font stack globally:
body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
Or to globally change the default border-radius used by components like buttons, alerts, cards, etc:
.btn, .alert, .card {
border-radius: 1rem;
}

Customizing the Grid
Bootstrap‘s flexbox grid system can also be customized via CSS overrides. While it‘s generally not recommended to change the default breakpoints and container widths, you can tweak things like grid gutters and padding:
.row {
margin-right: -5px;
margin-left: -5px;
}
.col, [class^="col-"] {
padding-right: 5px;
padding-left: 5px;
}
This would reduce the space between columns by half, from 30px to 15px.
Generating Custom Color Schemes
Bootstrap provides an extensive color system with semantic color names like "primary", "success", "warning", etc. These colors are used consistently across all of Bootstrap‘s components.
While you can override each component‘s colors individually, it‘s much easier to override the color system globally. Bootstrap provides Sass maps that define the HEX values for each semantic color name:
$theme-colors: (
"primary": #007bff,
"secondary": #6c757d,
"success": #28a745,
"warning": #ffc107,
"danger": #dc3545,
"light": #f8f9fa,
"dark": #343a40
);
In CSS, you can reference these semantic color names using CSS variables. To generate a custom color scheme, simply redefine the CSS variables with your desired HEX values:
:root {
--primary: #a71e7c;
--secondary: #76838f;
--success: #2ecc71;
--warning: #f1c40f;
--danger: #e74c3c;
--light: #ecf0f1;
--dark: #2c3e50;
}
Voila! You now have a complete, custom color scheme that will be applied consistently across all of Bootstrap‘s components:

Extending Bootstrap with Custom Classes
In addition to overriding Bootstrap‘s default classes, you can extend Bootstrap by creating your own custom classes.
For example, let‘s say you want a custom button variant that has a gradient background. Simply create a new class and add your desired styles:
.btn-gradient {
background-image: linear-gradient(to right, #ff8a00 0%, #da1b60 100%);
border: none;
transition: 0.5s;
}
.btn-gradient:hover {
background-image: linear-gradient(to right, #da1b60 0%, #ff8a00 100%);
}
Now you can use this new .btn-gradient class alongside Bootstrap‘s default button classes:
<button class="btn btn-gradient btn-lg">Gradient Button</button>

Method 2: Using Sass Variables
For more extensive and global customizations, using Bootstrap‘s Sass source files provides the most power and flexibility. With this method, instead of overriding the final generated CSS, you directly modify the Sass variables that generate Bootstrap‘s CSS.
The advantage of this method is that your customizations are baked right into Bootstrap‘s CSS, rather than relying on loading order and specificity to override the default styles. This results in a cleaner and more maintainable code base.
To use this method, you‘ll need to set up a Sass preprocessor and a build system to compile Bootstrap‘s Sass into CSS. How exactly this is done will depend on your development environment, but Bootstrap‘s docs provide setup instructions for several common build tools.
Customizing Bootstrap‘s Sass Variables
Once you have Bootstrap‘s Sass source importing into your own Sass files, you can begin customizing variables. Bootstrap 4 has around 500 Sass variables, all of which are defined in the _variables.scss file.
To override a default value, simply redefine the variable in your own Sass file before importing Bootstrap. For example:
// Your variable overrides
$body-bg: #000;
$body-color: #111;
// Bootstrap and its default variables
@import "../node_modules/bootstrap/scss/bootstrap";
This would change the default light background and text color to a dark scheme.
Some notable variables to customize include:
$font-family-base– The default font family$font-size-base– The default font size$border-radius– The default border radius size$enable-rounded– Enables predefined border-radius styles on various components$spacer– The default spacing unit (used for margin, padding, etc.)
Customizing Bootstrap‘s Sass Maps
Bootstrap also uses Sass maps extensively to manage things like colors, breakpoints, grid tiers, and more. These are defined as variables, but they use a slightly different syntax.
For example, here‘s the Sass map for Bootstrap‘s colors:
$theme-colors: (
"primary": $primary,
"secondary": $secondary,
"success": $success,
// etc
) !default;
To modify an existing color in the map:
$theme-colors: (
"primary": #a71e7c
);
Or to add a new custom color to the map:
$theme-colors: map-merge(
(
"gradientPurple": linear-gradient(to right, #ff8a00 0%, #da1b60 100%)
),
$theme-colors
);
Now you can reference your new gradientPurple color anywhere the $theme-colors map is used, like the .bg-* and .text-* classes, button variants, etc.
Best Practices for Customizing Bootstrap
Regardless of whether you use CSS overrides or Sass variables, there are some best practices to keep in mind when customizing Bootstrap:
- Avoid modifying Bootstrap‘s core files directly. Instead, always make customizations in your own separate CSS or Sass files. This will make upgrading Bootstrap much easier in the future.
- Use Chrome/Firefox DevTools extensively to inspect elements, see what styles are being applied, and test out customizations on the fly. The DevTools are your best friend when working with CSS and Bootstrap.
- Pay attention to specificity when overriding styles with custom CSS. If your styles aren‘t specific enough, they may get overridden by Bootstrap‘s defaults. Use the DevTools to see the computed specificity scores.
- If using Sass, make use of Bootstrap‘s mixins and functions to generate your own styles and components. This will help your custom code better integrate with the framework.
- Organize your code well and use comments liberally. Breaking your customizations into separate logical files (like
_variables.scss,_type.scss,_buttons.scssetc) can help maintainability. - Refer to Bootstrap‘s excellent documentation often, especially the Theming section which goes in-depth on customization techniques.
Conclusion
By using CSS overrides and/or Sass variables, it‘s possible to deeply customize Bootstrap to match any design or brand. The key is understanding how Bootstrap‘s styles are structured, and then systematically overriding them in your own code.
With the ability to customize everything from colors to fonts to spacing to component styles, you can adapt Bootstrap‘s powerful and flexible front-end system to suit your needs perfectly. By following best practices and keeping your code organized, customizing Bootstrap is a great way to accelerate development without sacrificing design flexibility.
So go forth and make Bootstrap your own! Implement your brand colors, tweak that border-radius, adjust those font sizes, and truly customize the framework to build something unique. Bootstrap‘s extensive customization options put the power in your hands to create something great.
Additional Resources
- Bootstrap‘s Theming Docs – Official guide to customizing Bootstrap
- Theming Bootstrap – Sample open source themed Bootstrap 4 site
- Sass Language Guide – Official Sass documentation
- Specificity Calculator – Visual way to understand CSS specificity
- Awesome Bootstrap – List of free Bootstrap themes and plugins
