Using Less
using-less
Bootstrap's CSS is built on Less, a preprocessor with additional functionality like variables, mixins, and functions for compiling CSS. Those looking to use the source Less files instead of our compiled CSS files can make use of the numerous variables and mixins we use throughout the framework.
Grid variables and mixins are covered within the Grid system section.
Compiling Bootstrap
Bootstrap can be used in at least two ways: with the compiled CSS or with the source Less files. To compile the Less files, consult the Getting Started section for how to setup your development environment to run the necessary commands.
Third party compilation tools may work with Bootstrap, but they are not supported by our core team.
Variables
Variables are used throughout the entire project as a way to centralize and share commonly used values like colors, spacing, or font stacks. For a complete breakdown, please see the Customizer.
Colors
Easily make use of two color schemes: grayscale and semantic. Grayscale colors provide quick access to commonly used shades of black while semantic include various colors assigned to meaningful contextual values.
Use any of these color variables as they are or reassign them to more meaningful variables for your project.
Scaffolding
A handful of variables for quickly customizing key elements of your site's skeleton.
Links
Easily style your links with the right color with only one value.
Note that the
@link-hover-color
uses a function, another awesome tool from Less, to automagically create the right hover color. You can usedarken
,lighten
,saturate
, anddesaturate
.Typography
Easily set your typeface, text size, leading, and more with a few quick variables. Bootstrap makes use of these as well to provide easy typographic mixins.
Icons
Two quick variables for customizing the location and filename of your icons.
Components
Components throughout Bootstrap make use of some default variables for setting common values. Here are the most commonly used.
Vendor Mixins
Vendor mixins are mixins to help support multiple browsers by including all relevant vendor prefixes in your compiled CSS.
Box Sizing
Reset your components' box model with a single mixin. For context, see this helpful article from Mozilla.
The mixin is deprecated as of v3.2.0, with the introduction of Autoprefixer. To preserve backwards-compatibility, Bootstrap will continue to use the mixin internally until Bootstrap v4.
Rounded Corners
Today all modern browsers support the non-prefixed
border-radius
property. As such, there is no.border-radius()
mixin, but Bootstrap does include shortcuts for quickly rounding two corners on a particular side of an object.Box (Drop) shadows
If your target audience is using the latest and greatest browsers and devices, be sure to just use the
box-shadow
property on its own. If you need support for older Android (pre-v4) and iOS devices (pre-iOS 5), use the deprecated mixin to pick up the required-webkit
prefix.The mixin is deprecated as of v3.1.0, since Bootstrap doesn't officially support the outdated platforms that don't support the standard property. To preserve backwards-compatibility, Bootstrap will continue to use the mixin internally until Bootstrap v4.
Be sure to use
rgba()
colors in your box shadows so they blend as seamlessly as possible with backgrounds.Transitions
Multiple mixins for flexibility. Set all transition information with one, or specify a separate delay and duration as needed.
The mixins are deprecated as of v3.2.0, with the introduction of Autoprefixer. To preserve backwards-compatibility, Bootstrap will continue to use the mixins internally until Bootstrap v4.
Transformations
Rotate, scale, translate (move), or skew any object.
The mixins are deprecated as of v3.2.0, with the introduction of Autoprefixer. To preserve backwards-compatibility, Bootstrap will continue to use the mixins internally until Bootstrap v4.
Animations
A single mixin for using all of CSS3's animation properties in one declaration and other mixins for individual properties.
The mixins are deprecated as of v3.2.0, with the introduction of Autoprefixer. To preserve backwards-compatibility, Bootstrap will continue to use the mixins internally until Bootstrap v4.
Opacity
Set the opacity for all browsers and provide a
filter
fallback for IE8.Placeholder Text
Provide context for form controls within each field.
Columns
Generate columns via CSS within a single element.
Gradients
Easily turn any two colors into a background gradient. Get more advanced and set a direction, use three colors, or use a radial gradient. With a single mixin you get all the prefixed syntaxes you'll need.
You can also specify the angle of a standard two-color, linear gradient:
If you need a barber-stripe style gradient, that's easy, too. Just specify a single color and we'll overlay a translucent white stripe.
Up the ante and use three colors instead. Set the first color, the second color, the second color's color stop (a percentage value like 25%), and the third color with these mixins:
Heads up! Should you ever need to remove a gradient, be sure to remove any IE-specific filter you may have added. You can do that by using the
.reset-filter()
mixin alongsidebackground-image: none;
.Utility Mixins
Utility mixins are mixins that combine otherwise unrelated CSS properties to achieve a specific goal or task.
Clearfix
Forget adding
class="clearfix"
to any element and instead add the.clearfix()
mixin where appropriate. Uses the micro clearfix from Nicolas Gallagher.Horizontal Centering
Quickly center any element within its parent. Requires width or max-width to be set.
Sizing Helpers
Specify the dimensions of an object more easily.
Resizable Textareas
Easily configure the resize options for any textarea, or any other element. Defaults to normal browser behavior
(both)
.Truncating Text
Easily truncate text with an ellipsis with a single mixin. Requires element to be block or inline-block level.
Retina images
Specify two image paths and the @1x image dimensions, and Bootstrap will provide an @2x media query. If you have many images to serve, consider writing your retina image CSS manually in a single media query.