Bootstrap is best maintained when you treat it as a separate and independently-versioned dependency in your development environment. Doing this makes upgrading Bootstrap easier in the future.
Once you've downloaded and included Bootstrap's styles and scripts, you can customize its components. Just create a new stylesheet (LESS, if you like, or just plain CSS) to house your customizations.
Compiled or minified?
Unless you plan on reading the CSS, go with minified stylesheets. It's the same code, just compacted. Minified styles use less bandwidth, which is good, especially in production environments.
From there, include whatever Bootstrap components and HTML content you need to create templates for your site's pages.
Customizing components
You can customize components to varying degrees, but most fall into two camps: light customizations and overhauls. Plenty examples of both are available from third parties.
We define light customizations as superficial changes, for example, color and font changes to existing Bootstrap components. A light customization example is the Twitter Translation Center (coded by @mdo). Let's look at how to implement the custom button we wrote for this site, .btn-ttc
.
The stock Bootstrap buttons require just one class, .btn
, to start. Here we extend the .btn
style with a new modifier class, .btn-ttc
, that we will create. This gives us a distinct custom look with minimal effort.
Our customized button will be coded like this:
<button type="button" class="btn btn-ttc">Save changes</button>
Note how .btn-ttc
is added to the standard .btn
class.
To implement this, in the custom stylesheet, add the following CSS:
/* Custom button
-------------------------------------------------- */
/* Override base .btn styles */
/* Apply text and background changes to three key states: default, hover, and active (click). */
.btn-ttc,
.btn-ttc:hover,
.btn-ttc:active {
color: white;
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
background-color: #007da7;
}
/* Apply the custom-colored gradients */
/* Note: you'll need to include all the appropriate gradients for various browsers and standards. */
.btn-ttc {
background-repeat: repeat-x;
background-image: linear-gradient(top, #009ED2 0%, #007DA7 100%);
...
}
/* Set the hover state */
/* An easy hover state is just to move the gradient up a small amount. Add other embellishments as you see fit. */
.btn-ttc:hover {
background-position: 0 -15px;
}
In short: Look to the style source and duplicate the selectors you need for your modifications.
In summary, here's the basic workflow:
- For each element you want to customize, find its code in the compiled Bootstrap CSS.
- Copy the component's selector and styles and paste them in your custom stylesheet. For instance, to customize the navbar background, just copy the
.navbar
style specification.
- In your custom stylesheet, edit the CSS you just copied from the Bootstrap source. No need for prepending additional classes, or appending
!important
here. Keep it simple.
- Rinse and repeat until you're happy with your customizations.
Once you are comfortable performing light customizations, visual overhauls are just as straightforward. For a site like Karma, which uses Bootstrap as a CSS reset with heavy modifications, more extensive work is involved. But the same principle applies: include Bootstrap's default stylesheet first, then apply your custom stylesheet.
Alternate customization methods
While not recommended for folks new to Bootstrap, you may use one of two alternate methods for customization. The first is modifying the source .less
files (making upgrades super difficult), and the second is mapping source LESS code to your own classes via mixins. For the time being, neither of those options are documented here.
Removing potential bloat
Not all sites and applications need to make use of everything Bootstrap has to offer, especially in production environments where optimizing bandwidth is an issue. We encourage you to remove whatever is unused with our Customizer.
Using the Customizer, simply uncheck any component, feature, or asset you don't need. Hit download and swap out the default Bootstrap files with these newly customized ones. You'll get vanilla Bootstrap, but without the features *you* deem unnecessary. All custom builds include compiled and minified versions, so use whichever works for you.