Customize and extend Bootstrap with LESS, a CSS preprocessor, to take advantage of the variables, mixins, and more used to build Bootstrap's CSS.
Bootstrap is made with LESS at it's core, a dynamic stylesheet language created by our good friend, Alexis Sellier. It makes developing systems-based CSS faster, easier, and more fun.
As an extension of CSS, LESS includes variables, mixins for reusable snippets of code, operations for simple math, nesting, and even color functions.
Visit the official website at http://lesscss.org to learn more.
Managing colors and pixel values in CSS can be a bit of a pain, usually full of copy and paste. Not with LESS though—assign colors or pixel values as variables and change them once.
Those three border-radius declarations you need to make in regular ol' CSS? Now they're down to one line with the help of mixins, snippets of code you can reuse anywhere.
Make your grid, leading, and more super flexible by doing the math on the fly with operations. Multiple, divide, add, and subtract your way to CSS sanity.
Variable | Value | Usage |
---|---|---|
@linkColor |
#08c | Default link text color |
@linkColorHover |
darken(@linkColor, 15%) |
Default link text hover color |
Variable | Value |
---|---|
@black |
#000 |
@grayDarker |
#222 |
@grayDark |
#333 |
@gray |
#555 |
@grayLight |
#999 |
@grayLighter |
#eee |
@white |
#fff |
Variable | Value |
---|---|
@blue |
#049cdb |
@green |
#46a546 |
@red |
#9d261d |
@yellow |
#ffc40d |
@orange |
#f89406 |
@pink |
#c3325f |
@purple |
#7a43b6 |
Variable | Value |
---|---|
@gridColumns |
12 |
@gridColumnWidth |
60px |
@gridGutterWidth |
20px |
@siteWidth |
(@gridColumns * @gridColumnWidth) + (@gridGutterWidth * (@gridColumns - 1)) |
Variable | Value | |
---|---|---|
@baseFontSize |
13px | |
@baseFontFamily |
"Helvetica Neue", Helvetica, Arial, sans-serif |
|
@baseLineHeight |
18px |
@primaryButtonColor |
@blue |
@placeholderText |
@grayLight |
@navbarHeight |
40px |
@navbarBackground |
@grayDarker |
@navbarBackgroundHighlight |
@grayDark |
@warningText |
#f3edd2 |
@warningBackground |
#c09853 |
@warningBorder |
#f3edd2 |
@errorText |
#b94a48 |
@errorBackground |
#f2dede |
@errorBorder |
#e9c7c7 |
@successText |
#468847 |
@successBackground |
#dff0d8 |
@successBorder |
#cfe8c4 |
@infoText |
#3a87ad |
@infoBackground |
#d9edf7 |
@infoBorder |
#bfe1f2 |
A basic mixin is essentially an include or a partial for a snippet of CSS. They're written just like a CSS class and can be called anywhere.
Coming soon!
A parametric mixin is just like a basic mixin, but it also accepts optional paramaters (hence the name).
Coming soon!
Nearly all of Bootstrap's mixins are stored in mixins.less, a wonderful utility .less file that enables you to use a mixin in any of the .less files in the toolkit.
So, go ahead and use the existing ones or feel free to add your own as you need.
Mixin | Paramaters | Usage |
---|---|---|
.clearfix() |
||
.center-block() |
||
.ie7-inline-block() |
||
.size() |
||
.square() |
||
.opacity() |
||
.reset-filter() |
Mixin | Paramaters | Usage |
---|---|---|
.placeholder() |
Mixin | Paramaters | Usage |
---|---|---|
#font > #family > .serif() |
||
#font > #family > .sans-serif() |
||
#font > #family > .monospace() |
||
#font > .shorthand() |
||
#font > .serif() |
||
#font > .sans-serif() |
||
#font > .monospace() |
Mixin | Paramaters | Usage |
---|---|---|
.fixed-container() |
||
.columns() |
||
.offset() |
||
.gridColumn() |
Mixin | Paramaters | Usage |
---|---|---|
.border-radius() |
||
.border-radius-custom() |
||
.box-shadow() |
||
.transition() |
||
.rotate() |
||
.scale() |
||
.translate() |
||
.background-clip() |
||
.background-size() |
||
.box-sizing() |
||
.user-select() |
||
.resizable() |
||
.content-columns() |
Mixin | Paramaters | Usage |
---|---|---|
.#translucent > .background() |
||
.#translucent > .border() |
||
.#gradient > .vertical() |
||
.#gradient > .horizontal() |
||
.#gradient > .directional() |
||
.#gradient > .vertical-three-colors() |
||
.#gradient > .radial() |
||
.#gradient > .striped() |
||
.#gradientBar() |
Install the LESS command line compiler with npm by running the following command:
$ npm install less
Once installed just run make
from the root of your bootstrap directory and you're all set.
Additionally, if you have watchr installed, you may run make watch
to have bootstrap automatically rebuilt every time you edit a file in the bootstrap lib (this isn't required, just a convenience method).
Install the LESS command line tool via Node and run the following command:
$ lessc ./lib/bootstrap.less > bootstrap.css
Be sure to include --compress
in that command if you're trying to save some bytes!
Download the latest Less.js and include the path to it (and Bootstrap) in the <head>
.
<link rel="stylesheet/less" href="/path/to/bootstrap.less"> <script src="/path/to/less.js"></script>
To recompile the .less files, just save them and reload your page. Less.js compiles them and stores them in local storage.
The unofficial Mac app watches directories of .less files and compiles the code to local files after every save of a watched .less file.
If you like, you can toggle preferences in the app for automatic minifying and which directory the compiled files end up in.
Crunch is a great looking LESS editor and compiler built on Adobe Air.
Created by the same guy as the unofficial Mac app, CodeKit is a Mac app that compiles LESS, SASS, Stylus, and CoffeeScript.
Mac, Linux, and PC app for drag and drop compiling of LESS files. Plus, the source code is on GitHub.