CSS Bootstrap
CSS Bootstrap
Overview
Get the lowdown on the key pieces of Bootstrap's infrastructure, including our
approach to better, faster, stronger web development.
HTML5 doctype
Bootstrap makes use of certain HTML elements and CSS properties that require the use of the HTML5 doctype.
Include it at the beginning of all your projects.
Copy
<!DOCTYPE html>
<html lang="en">
...
</html>
Mobile first
With Bootstrap 2, w e added optional mobile friendly styles for key aspects of the framew ork. With Bootstrap 3,
w e've rew ritten the project to be mobile friendly from the start. Instead of adding on optional mobile styles,
they're baked right into the core. In fact, Bootstrap is m obile first. Mobile first styles can be found throughout
the entire library instead of in separate files.
To ensure proper rendering and touch zooming, add the view port m eta tag to your <head> .
<meta name="viewport" content="width=devicewidth, initialscale=1">
Copy
You can disable zooming capabilities on mobile devices by adding userscalable=no to the view port meta tag.
This disables zooming, meaning users are only able to scroll, and results in your site feeling a bit more like a
native application. Overall, w e don't recommend this on every site, so use caution!
<meta name="viewport" content="width=devicewidth, initialscale=1, maximumscale=1,
userscalable=no">
Copy
Normalize.css
1 of 63
1 of 63
For improved cross-brow ser rendering, w e use Normalize.css, a project by Nicolas Gallagher and Jonathan
Neal.
Containers
Bootstrap requires a containing element to w rap site contents and house our grid system. You may choose one
of tw o containers to use in your projects. Note that, due to padding and more, neither container is nestable.
Use .container for a responsive fixed w idth container.
Copy
<div class="container">
...
</div>
Use .containerfluid for a full w idth container, spanning the entire w idth of your view port.
Copy
<div class="containerfluid">
...
</div>
Grid system
Bootstrap includes a responsive, mobile first fluid grid system that
appropriately scales up to 12 columns as the device or viewport size
increases. It includes predefined classes for easy layout options, as well as
powerful mixins for generating more semantic layouts.
Introduction
Grid systems are used for creating page layouts through a series of row s and columns that house your
content. Here's how the Bootstrap grid system w orks:
Row s must be placed w ithin a .container (fixed-w idth) or .containerfluid (full-w idth) for proper
alignment and padding.
Use row s to create horizontal groups of columns.
Content should be placed w ithin columns, and only columns may be immediate children of row s.
Predefined grid classes like .row and .colxs4 are available for quickly making grid layouts. Less
mixins can also be used for more semantic layouts.
Columns create gutters (gaps betw een column content) via padding . That padding is offset in row s for
the first and last column via negative margin on .row s.
The negative margin is w hy the examples below are outdented. It's so that content w ithin grid columns is
lined up w ith non-grid content.
Grid columns are created by specifying the number of tw elve available columns you w ish to span. For
example, three equal columns w ould use three .colxs4 .
If more than 12 columns are placed w ithin a single row , each group of extra columns w ill, as one unit,
w rap onto a new line.
Grid classes apply to devices w ith screen w idths greater than or equal to the breakpoint sizes, and
override grid classes targeted at smaller devices. Therefore, applying any .colmd class to an element
2 of 63
2 of 63
w ill not only affect its styling on medium devices but also on large devices if a .collg class is not
present.
Look to the examples for applying these principles to your code.
Media queries
We use the follow ing media queries in our Less files to create the key breakpoints in our grid system.
Copy
We occasionally expand on these media queries to include a maxwidth to limit CSS to a narrow er set of
devices.
@media
@media
@media
@media
(maxwidth:
(minwidth:
(minwidth:
(minwidth:
@screenxsmax)
@screensmmin)
@screenmdmin)
@screenlgmin)
Copy
{ ... }
and (maxwidth: @screensmmax) { ... }
and (maxwidth: @screenmdmax) { ... }
{ ... }
Grid options
See how aspects of the Bootstrap grid system w ork across multiple devices w ith a handy table.
Extra sm all
devices Phones
Sm all devices
Medium devices
Large devices
(<768px)
Tablets (768px)
Desktops (992px)
Desktops (1200px)
Grid behavior
Container w idth
None (auto)
750px
Class prefix
.colxs
970px
.colsm
# of colum ns
12
Colum n w idth
Auto
Gutter w idth
Nestable
Yes
Offsets
Yes
Colum n ordering
Yes
~62px
.colmd
~81px
3 of 63
1170px
.collg
~97px
3 of 63
Example: Stacked-to-horizontal
Using a single set of .colmd* grid classes, you can create a basic grid system that starts out stacked on
mobile devices and tablet devices (the extra small to small range) before becoming horizontal on desktop
(medium) devices. Place grid columns in any .row .
.col-md-1
.col-md-1
.col-md-1
.col-md-1
.col-md-1
.col-md-1
.col-md-1
.col-md-1
.col-md-1
.col-md-1
.col-md-1
.col-md-1
.col-md-8
.col-md-4
.col-md-4
.col-md-4
.col-md-4
.col-md-6
.col-md-6
Copy
4 of 63
4 of 63
<div class="row">
<div class="colmd1">.colmd1</div>
<div class="colmd1">.colmd1</div>
<div class="colmd1">.colmd1</div>
<div class="colmd1">.colmd1</div>
<div class="colmd1">.colmd1</div>
<div class="colmd1">.colmd1</div>
<div class="colmd1">.colmd1</div>
<div class="colmd1">.colmd1</div>
<div class="colmd1">.colmd1</div>
<div class="colmd1">.colmd1</div>
<div class="colmd1">.colmd1</div>
<div class="colmd1">.colmd1</div>
</div>
<div class="row">
<div class="colmd8">.colmd8</div>
<div class="colmd4">.colmd4</div>
</div>
<div class="row">
<div class="colmd4">.colmd4</div>
<div class="colmd4">.colmd4</div>
<div class="colmd4">.colmd4</div>
</div>
<div class="row">
<div class="colmd6">.colmd6</div>
<div class="colmd6">.colmd6</div>
</div>
<div class="containerfluid">
<div class="row">
...
</div>
</div>
.col-xs-6 .col-md-4
.col-xs-6 .col-md-4
.col-xs-6 .col-md-4
5 of 63
5 of 63
.col-xs-6
.col-xs-6
<! Stack the columns on mobile by making one fullwidth and the other halfwidth >
<div class="row">
<div class="colxs12 colmd8">.colxs12 .colmd8</div>
<div class="colxs6 colmd4">.colxs6 .colmd4</div>
</div>
Copy
<! Columns start at 50% wide on mobile and bump up to 33.3% wide on desktop >
<div class="row">
<div class="colxs6 colmd4">.colxs6 .colmd4</div>
<div class="colxs6 colmd4">.colxs6 .colmd4</div>
<div class="colxs6 colmd4">.colxs6 .colmd4</div>
</div>
<! Columns are always 50% wide, on mobile and desktop >
<div class="row">
<div class="colxs6">.colxs6</div>
<div class="colxs6">.colxs6</div>
</div>
.col-xs-6 .col-sm-4
.col-xs-6 .col-md-4
.col-xs-6 .col-sm-4
.col-xs-6 .col-sm-4
<div class="row">
<div class="colxs12 colsm6 colmd8">.colxs12 .colsm6 .colmd8</div>
<div class="colxs6 colmd4">.colxs6 .colmd4</div>
</div>
<div class="row">
<div class="colxs6 colsm4">.colxs6 .colsm4</div>
<div class="colxs6 colsm4">.colxs6 .colsm4</div>
<! Optional: clear the XS cols if their content doesn't match in height >
<div class="clearfix visiblexsblock"></div>
<div class="colxs6 colsm4">.colxs6 .colsm4</div>
</div>
Copy
.col-xs-6
Subsequent columns continue along the new line.
6 of 63
6 of 63
<div class="row">
<div class="colxs9">.colxs9</div>
<div class="colxs4">.colxs4<br>Since 9 + 4 = 13 > 12, this 4columnwide div gets
wrapped onto a new line as one contiguous unit.</div>
<div class="colxs6">.colxs6<br>Subsequent columns continue along the new line.</div>
</div>
Copy
.col-xs-6 .col-sm-3
.col-xs-6 .col-sm-3
.col-xs-6 .col-sm-3
<div class="row">
<div class="colxs6 colsm3">.colxs6 .colsm3</div>
<div class="colxs6 colsm3">.colxs6 .colsm3</div>
Copy
<! Add the extra clearfix for only the required viewport >
<div class="clearfix visiblexsblock"></div>
<div class="colxs6 colsm3">.colxs6 .colsm3</div>
<div class="colxs6 colsm3">.colxs6 .colsm3</div>
</div>
In addition to column clearing at responsive breakpoints, you may need to reset offsets, pushes, or pulls.
See this in action in the grid example.
<div class="row">
<div class="colsm5 colmd6">.colsm5 .colmd6</div>
<div class="colsm5 colsmoffset2 colmd6 colmdoffset0">.colsm5 .colsmoffset2
.colmd6 .colmdoffset0</div>
</div>
Copy
<div class="row">
<div class="colsm6 colmd5 collg6">.colsm6 .colmd5 .collg6</div>
<div class="colsm6 colmd5 colmdoffset2 collg6 collgoffset0">.colsm6 .colmd5
.colmdoffset2 .collg6 .collgoffset0</div>
</div>
Offsetting columns
Move columns to the right using .colmdoffset* classes. These classes increase the left margin of a column
by * columns. For example, .colmdoffset4 moves .colmd4 over four columns.
7 of 63
7 of 63
.col-md-4
.col-md-4 .col-md-offset-4
.col-md-3 .col-md-offset-3
.col-md-3 .col-md-offset-3
.col-md-6 .col-md-offset-3
<div class="row">
<div class="colmd4">.colmd4</div>
<div class="colmd4 colmdoffset4">.colmd4
</div>
<div class="row">
<div class="colmd3 colmdoffset3">.colmd3
<div class="colmd3 colmdoffset3">.colmd3
</div>
<div class="row">
<div class="colmd6 colmdoffset3">.colmd6
</div>
Copy
.colmdoffset4</div>
.colmdoffset3</div>
.colmdoffset3</div>
.colmdoffset3</div>
Nesting columns
To nest your content w ith the default grid, add a new .row and set of .colsm* columns w ithin an existing
.colsm* column. Nested row s should include a set of columns that add up to 12 or less (it is not required that
you use all 12 available columns).
Level 1: .col-sm-9
Level 2: .col-xs-8 .col-sm-6
<div class="row">
<div class="colsm9">
Level 1: .colsm9
<div class="row">
<div class="colxs8
Level 2: .colxs8
</div>
<div class="colxs4
Level 2: .colxs4
</div>
</div>
</div>
</div>
Copy
colsm6">
.colsm6
colsm6">
.colsm6
Column ordering
Easily change the order of our built-in grid columns w ith .colmdpush* and .colmdpull* modifier classes.
8 of 63
8 of 63
.col-md-9 .col-md-push-3
.col-md-3 .col-md-pull-9
<div class="row">
<div class="colmd9 colmdpush3">.colmd9 .colmdpush3</div>
<div class="colmd3 colmdpull9">.colmd3 .colmdpull9</div>
</div>
Copy
Variables
Variables determine the number of columns, the gutter w idth, and the media query point at w hich to begin
floating columns. We use these to generate the predefined grid classes documented above, as w ell as for the
custom mixins listed below .
@gridcolumns:
@gridgutterwidth:
@gridfloatbreakpoint:
Copy
12;
30px;
768px;
Mixins
Mixins are used in conjunction w ith the grid variables to generate semantic CSS for individual grid columns.
Copy
9 of 63
9 of 63
10 of 63
10 of 63
Example usage
You can modify the variables to your ow n custom values, or just use the mixins w ith their default values. Here's
an example of using the default settings to create a tw o-column layout w ith a gap betw een.
.wrapper {
.makerow();
}
.contentmain {
.makelgcolumn(8);
}
.contentsecondary {
.makelgcolumn(3);
.makelgcolumnoffset(1);
}
Copy
<div class="wrapper">
<div class="contentmain">...</div>
<div class="contentsecondary">...</div>
</div>
Copy
Typography
Headings
All HTML headings, <h1> through <h6> , are available. .h1 through .h6 classes are also available, for w hen
you w ant to match the font styling of a heading but still w ant your text to be displayed inline.
EXAMPL E
Semibold 36px
Semibold 30px
Semibold 24px
Semibold 18px
Semibold 14px
Semibold 12px
Copy
11 of 63
11 of 63
<h1>h1.
<h2>h2.
<h3>h3.
<h4>h4.
<h5>h5.
<h6>h6.
Bootstrap
Bootstrap
Bootstrap
Bootstrap
Bootstrap
Bootstrap
heading</h1>
heading</h2>
heading</h3>
heading</h4>
heading</h5>
heading</h6>
Create lighter, secondary text in any heading w ith a generic <small> tag or the .small class.
EXAMPL E
Secondary text
Secondary text
<h1>h1.
<h2>h2.
<h3>h3.
<h4>h4.
<h5>h5.
<h6>h6.
Bootstrap
Bootstrap
Bootstrap
Bootstrap
Bootstrap
Bootstrap
heading
heading
heading
heading
heading
heading
<small>Secondary
<small>Secondary
<small>Secondary
<small>Secondary
<small>Secondary
<small>Secondary
text</small></h1>
text</small></h2>
text</small></h3>
text</small></h4>
text</small></h5>
text</small></h6>
Copy
Body copy
Bootstrap's global default fontsize is 14px, w ith a lineheight of 1.428. This is applied to the <body> and all
paragraphs. In addition, <p> (paragraphs) receive a bottom margin of half their computed line-height (10px by
default).
EXAMPL E
Nullam quis risus eget urna mollis ornare vel eu leo. Cum sociis natoque penatibus et magnis dis parturient
montes, nascetur ridiculus mus. Nullam id dolor id nibh ultricies vehicula.
Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec ullamcorper
nulla non metus auctor fringilla. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia
odio sem nec elit. Donec ullamcorper nulla non metus auctor fringilla.
Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget
metus. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit.
Copy
12 of 63
12 of 63
<p>...</p>
Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Duis
mollis, est non commodo luctus.
Copy
<p class="lead">...</p>
Copy
Deleted text
For indicating blocks of text that have been deleted use the <del> tag.
EXAMPL E
Copy
Strikethrough text
For indicating blocks of text that are no longer relevant use the <s> tag.
EXAMPL E
13 of 63
13 of 63
Inserted text
For indicating additions to the document use the <ins> tag.
EXAMPL E
Copy
Underlined text
To underline text use the <u> tag.
EXAMPL E
Copy
Make use of HTML's default emphasis tags w ith lightw eight styles.
Small text
For de-emphasizing inline or blocks of text, use the <small> tag to set text at 85% the size of the parent.
Heading elements receive their ow n fontsize for nested <small> elements.
You may alternatively use an inline element w ith .small in place of any <small> .
EXAMPL E
This line of text is meant to be treated as f ine print.
Copy
Bold
For emphasizing a snippet of text w ith a heavier font-w eight.
EXAMPL E
Italics
For emphasizing a snippet of text w ith italics.
14 of 63
14 of 63
EXAMPL E
Alternate elements
Feel free to use <b> and <i> in HTML5. <b> is meant to highlight w ords or phrases w ithout conveying
additional importance w hile <i> is mostly for voice, technical terms, etc.
Alignment classes
Easily realign text to components w ith text alignment classes.
EXAMPL E
Copy
Transformation classes
Transform text in components w ith text capitalization classes.
EXAMPL E
Abbreviations
Stylized implementation of HTML's <abbr> element for abbreviations and acronyms to show the expanded
version on hover. Abbreviations w ith a title attribute have a light dotted bottom border and a help cursor on
15 of 63
15 of 63
Basic abbreviation
For expanded text on long hover of an abbreviation, include the title attribute w ith the <abbr> element.
EXAMPL E
<abbr title="attribute">attr</abbr>
Initialism
Add .initialism to an abbreviation for a slightly smaller font-size.
EXAMPL E
HTML
Copy
Addresses
Present contact information for the nearest ancestor or the entire body of w ork. Preserve formatting by ending
all lines w ith <br> .
EXAMPL E
Tw itter, Inc.
795 Folsom Ave, Suite 600
San Francisco, CA 94107
P: (123) 456-7890
Full Nam e
first.last@example.com
Copy
<address>
<strong>Twitter, Inc.</strong><br>
795 Folsom Ave, Suite 600<br>
San Francisco, CA 94107<br>
<abbr title="Phone">P:</abbr> (123) 4567890
</address>
<address>
<strong>Full Name</strong><br>
<a href="mailto:#">first.last@example.com</a>
</address>
Blockquotes
For quoting blocks of content from another source w ithin your document.
16 of 63
16 of 63
Default blockquote
Wrap <blockquote> around any HTML as the quote. For straight quotes, w e recommend a <p> .
EXAMPL E
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a
ante.
<blockquote>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a ante.</p>
</blockquote>
Copy
Blockquote options
Style and content changes for simple variations on a standard <blockquote> .
Naming a source
Add a <footer> for identifying the source. Wrap the name of the source w ork in <cite> .
EXAMPL E
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a
ante.
Someone famous in Source Title
<blockquote>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a ante.</p>
<footer>Someone famous in <cite title="Source Title">Source Title</cite></footer>
</blockquote>
Copy
Alternate displays
Add .blockquotereverse for a blockquote w ith right-aligned content.
EXAMPL E
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a ante.
Someone famous in Source Title
Copy
<blockquote class="blockquotereverse">
...
</blockquote>
Lists
Unordered
17 of 63
17 of 63
<ul>
<li>...</li>
</ul>
Ordered
A list of items in w hich the order does explicitly matter.
EXAMPL E
1.
2.
3.
4.
5.
6.
7.
8.
<ol>
<li>...</li>
</ol>
Unstyled
Remove the default liststyle and left margin on list items (immediate children only). This only applies to
im m ediate children list item s, meaning you w ill need to add the class for any nested lists as w ell.
EXAMPL E
18 of 63
<ul class="listunstyled">
<li>...</li>
</ul>
Inline
Place all list items on a single line w ith display: inlineblock; and some light padding.
EXAMPL E
<ul class="listinline">
<li>...</li>
</ul>
Description
A list of terms w ith their associated descriptions.
EXAMPL E
Description lists
A description list is perfect for defining terms.
Euism od
Vestibulum id ligula porta felis euismod semper eget lacinia odio sem nec elit.
Donec id elit non mi porta gravida at eget metus.
Malesuada porta
Etiam porta sem malesuada magna mollis euismod.
Copy
<dl>
<dt>...</dt>
<dd>...</dd>
</dl>
Horizontal description
Make terms and descriptions in <dl> line up side-by-side. Starts off stacked like default <dl> s, but w hen the
navbar expands, so do these.
EXAMPL E
Description lists
Euism od
Malesuada porta
Felis euism od sem ...
19 of 63
Copy
<dl class="dlhorizontal">
<dt>...</dt>
<dd>...</dd>
</dl>
Auto-truncating
Horizontal description lists w ill truncate terms that are too long to fit in the left column w ith
textoverflow . In narrow er view ports, they w ill change to the default stacked layout.
Code
Inline
Wrap inline snippets of code w ith <code> .
EXAMPL E
Copy
User input
Use the <kbd> to indicate input that is typically entered via keyboard.
EXAMPL E
Copy
Basic block
Use <pre> for multiple lines of code. Be sure to escape any angle brackets in the code for proper rendering.
EXAMPL E
20 of 63
20 of 63
Copy
You may optionally add the .prescrollable class, w hich w ill set a max-height of 350px and provide a y-axis
scrollbar.
Variables
For indicating variables use the <var> tag.
EXAMPL E
y = mx + b
Copy
Sample output
For indicating blocks sample output from a program use the <samp> tag.
EXAMPL E
Copy
Tables
Basic example
For basic stylinglight padding and only horizontal dividersadd the base class .table to any <table> . It may
seem super redundant, but given the w idespread use of tables for other plugins like calendars and date
pickers, w e've opted to isolate our custom table styles.
EXAMPL E
First Nam e
Last Nam e
Usernam e
Mark
Otto
@mdo
Jacob
Thornton
@fat
Larry
the Bird
@tw itter
Copy
21 of 63
21 of 63
<table class="table">
...
</table>
Striped rows
Use .tablestriped to add zebra-striping to any table row w ithin the <tbody> .
Cross-browser compatibility
Striped tables are styled via the :nthchild CSS selector, w hich is not available in Internet Explorer 8.
EXAMPL E
First Nam e
Last Nam e
Usernam e
Mark
Otto
@mdo
Jacob
Thornton
@fat
Larry
the Bird
@tw itter
Copy
Bordered table
Add .tablebordered for borders on all sides of the table and cells.
EXAMPL E
First Nam e
Last Nam e
Usernam e
Mark
Otto
@mdo
Mark
Otto
@Tw Bootstrap
Jacob
Thornton
@fat
@tw itter
Copy
Hover rows
Add .tablehover to enable a hover state on table row s w ithin a <tbody> .
22 of 63
22 of 63
EXAMPL E
First Nam e
Last Nam e
Usernam e
Mark
Otto
@mdo
Jacob
Thornton
@fat
@tw itter
Copy
Condensed table
Add .tablecondensed to make tables more compact by cutting cell padding in half.
EXAMPL E
First Nam e
Last Nam e
Usernam e
Mark
Otto
@mdo
Jacob
Thornton
@fat
@tw itter
Copy
Contextual classes
Use contextual classes to color table row s or individual cells.
Class
Description
.active
.success
.info
.warning
.danger
EXAMPL E
Colum n heading
Colum n heading
23 of 63
Colum n heading
23 of 63
Colum n heading
Colum n heading
Colum n heading
Column content
Column content
Column content
Column content
Column content
Column content
Column content
Column content
Column content
Column content
Column content
Column content
Column content
Column content
Column content
Column content
Column content
Column content
Column content
Column content
Column content
Column content
Column content
Column content
Column content
Column content
Column content
Copy
Responsive tables
Create responsive tables by w rapping any .table in .tableresponsive to make them scroll horizontally on
small devices (under 768px). When view ing on anything larger than 768px w ide, you w ill not see any
difference in these tables.
@mozdocument urlprefix() {
fieldset { display: tablecell; }
}
24 of 63
24 of 63
EXAMPL E
Table
heading
Table
heading
Table
heading
Table
heading
Table
heading
Table
heading
Table cell
Table cell
Table cell
Table cell
Table cell
Table cell
Table cell
Table cell
Table cell
Table cell
Table cell
Table cell
Table cell
Table cell
Table cell
Table cell
Table cell
Table cell
Table
heading
Table
heading
Table
heading
Table
heading
Table
heading
Table
heading
Table cell
Table cell
Table cell
Table cell
Table cell
Table cell
Table cell
Table cell
Table cell
Table cell
Table cell
Table cell
Table cell
Table cell
Table cell
Table cell
Table cell
Table cell
Copy
<div class="tableresponsive">
<table class="table">
...
</table>
</div>
Forms
Basic example
Individual form controls automatically receive some global styling. All textual <input> , <textarea> , and
<select> elements w ith .formcontrol are set to width: 100%; by default. Wrap labels and controls in
.formgroup for optimum spacing.
EXAMPL E
Em ail address
Enter email
Passw ord
Passw ord
File input
Browse
No file selected.
25 of 63
Check me out
Submit
<form role="form">
<div class="formgroup">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="formcontrol" id="exampleInputEmail1" placeholder="Enter email">
</div>
<div class="formgroup">
<label for="exampleInputPassword1">Password</label>
<input type="password" class="formcontrol" id="exampleInputPassword1"
placeholder="Password">
</div>
<div class="formgroup">
<label for="exampleInputFile">File input</label>
<input type="file" id="exampleInputFile">
<p class="helpblock">Example blocklevel help text here.</p>
</div>
<div class="checkbox">
<label>
<input type="checkbox"> Check me out
</label>
</div>
<button type="submit" class="btn btndefault">Submit</button>
</form>
Copy
Inline form
Add .forminline to your <form> for left-aligned and inline-block controls. This only applies to form s
w ithin view ports that are at least 768px w ide.
26 of 63
26 of 63
EXAMPL E
Enter email
Passw ord
Enter email
Remember me Sign in
<form class="forminline" role="form">
<div class="formgroup">
<label class="sronly" for="exampleInputEmail2">Email address</label>
<input type="email" class="formcontrol" id="exampleInputEmail2" placeholder="Enter email">
</div>
<div class="formgroup">
<div class="inputgroup">
<div class="inputgroupaddon">@</div>
<input class="formcontrol" type="email" placeholder="Enter email">
</div>
</div>
<div class="formgroup">
<label class="sronly" for="exampleInputPassword2">Password</label>
<input type="password" class="formcontrol" id="exampleInputPassword2"
placeholder="Password">
</div>
<div class="checkbox">
<label>
<input type="checkbox"> Remember me
</label>
</div>
<button type="submit" class="btn btndefault">Sign in</button>
</form>
Copy
Horizontal form
Use Bootstrap's predefined grid classes to align labels and groups of form controls in a horizontal layout by
adding .formhorizontal to the form. Doing so changes .formgroup s to behave as grid row s, so no need for
.row .
EXAMPL E
Em ail
Passw ord
Email
Passw ord
Remember me
Sign in
Copy
27 of 63
27 of 63
Supported controls
Examples of standard form controls supported in an example form layout.
Inputs
Most common form control, text-based input fields. Includes support for all HTML5 types: text , password ,
datetime , datetimelocal , date , month , time , week , number , email , url , search , tel , and color .
EXAMPL E
Text input
Copy
Input groups
To add integrated text or buttons before and/or after any text-based <input> , check out the input group
28 of 63
28 of 63
component.
Textarea
Form control w hich supports multiple lines of text. Change rows attribute as necessary.
EXAMPL E
Copy
Default (stacked)
EXAMPL E
29 of 63
29 of 63
<div class="checkbox">
<label>
<input type="checkbox" value="">
Option one is this and that—be sure to include why it's great
</label>
</div>
<div class="checkbox disabled">
<label>
<input type="checkbox" value="" disabled>
Option two is disabled
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="optionsRadios" id="optionsRadios1" value="option1" checked>
Option one is this and that—be sure to include why it's great
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="optionsRadios" id="optionsRadios2" value="option2">
Option two can be something else and selecting it will deselect option one
</label>
</div>
<div class="radio disabled">
<label>
<input type="radio" name="optionsRadios" id="optionsRadios3" value="option3" disabled>
Option three is disabled
</label>
</div>
3
Copy
30 of 63
30 of 63
<label class="checkboxinline">
<input type="checkbox" id="inlineCheckbox1" value="option1"> 1
</label>
<label class="checkboxinline">
<input type="checkbox" id="inlineCheckbox2" value="option2"> 2
</label>
<label class="checkboxinline">
<input type="checkbox" id="inlineCheckbox3" value="option3"> 3
</label>
<label class="radioinline">
<input type="radio" name="inlineRadioOptions" id="inlineRadio1" value="option1"> 1
</label>
<label class="radioinline">
<input type="radio" name="inlineRadioOptions" id="inlineRadio2" value="option2"> 2
</label>
<label class="radioinline">
<input type="radio" name="inlineRadioOptions" id="inlineRadio3" value="option3"> 3
</label>
<div class="checkbox">
<label>
<input type="checkbox" id="blankCheckbox" value="option1">
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="blankRadio" id="blankRadio1" value="option1">
</label>
</div>
Copy
Selects
Use the default option, or add multiple to show multiple options at once.
EXAMPL E
31 of 63
31 of 63
1
2
3
4
5
Copy
<select class="formcontrol">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
<select multiple class="formcontrol">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
Static control
When you need to place plain text next to a form label w ithin a form, use the .formcontrolstatic class on a
<p> .
EXAMPL E
Em ail
Passw ord
email@example.com
Passw ord
Copy
EXAMPL E
Confirm identity
Copy
32 of 63
32 of 63
Input focus
We remove the default outline styles on some form controls and apply a boxshadow in its place for :focus .
EXAMPL E
Disabled inputs
Add the disabled boolean attribute on an input to prevent user input and trigger a slightly different look.
EXAMPL E
Copy
Disabled fieldsets
Add the disabled attribute to a <fieldset> to disable all the controls w ithin the <fieldset> at once.
Cross-browser compatibility
33 of 63
33 of 63
While Bootstrap w ill apply these styles in all brow sers, Internet Explorer 11 and below don't fully support
the disabled attribute on a <fieldset> . Use custom JavaScript to disable the fieldset in these brow sers.
EXAMPL E
Disabled input
Disabled input
Disabled select m enu
Disabled select
Can't check this
<form role="form">
<fieldset disabled>
<div class="formgroup">
<label for="disabledTextInput">Disabled input</label>
<input type="text" id="disabledTextInput" class="formcontrol" placeholder="Disabled
input">
</div>
<div class="formgroup">
<label for="disabledSelect">Disabled select menu</label>
<select id="disabledSelect" class="formcontrol">
<option>Disabled select</option>
</select>
</div>
<div class="checkbox">
<label>
<input type="checkbox"> Can't check this
</label>
</div>
<button type="submit" class="btn btnprimary">Submit</button>
</fieldset>
</form>
Copy
Readonly inputs
Add the readonly boolean attribute on an input to prevent user input and style the input as disabled.
EXAMPL E
Copy
Validation states
Bootstrap includes validation styles for error, w arning, and success states on form controls. To use, add
34 of 63
34 of 63
EXAMPL E
35 of 63
35 of 63
EXAMPL E
36 of 63
Copy
Copy
EXAMPL E
Copy
37 of 63
37 of 63
Copy
Control sizing
Set heights using classes like .inputlg , and set w idths using grid column classes like .collg* .
Height sizing
Create taller or shorter form controls that match button sizes.
EXAMPL E
.input-lg
Default input
.input-sm
.input-lg
Default select
.input-sm
Copy
38 of 63
38 of 63
Large label
Sm all label
Large input
Small input
Copy
Column sizing
Wrap inputs in grid columns, or any custom parent element, to easily enforce desired w idths.
EXAMPL E
.col-xs-2
.col-xs-3
.col-xs-4
Copy
39 of 63
39 of 63
<div class="row">
<div class="colxs2">
<input type="text" class="formcontrol" placeholder=".colxs2">
</div>
<div class="colxs3">
<input type="text" class="formcontrol" placeholder=".colxs3">
</div>
<div class="colxs4">
<input type="text" class="formcontrol" placeholder=".colxs4">
</div>
</div>
Help text
Block level help text for form controls.
EXAMPL E
A block of help text that breaks onto a new line and may extend beyond one line.
<span class="helpblock">A block of help text that breaks onto a new line and may extend beyond
one line.</span>
Copy
Buttons
Options
Use any of the available button classes to quickly create a styled button.
EXAMPL E
Copy
40 of 63
40 of 63
Sizes
Fancy larger or smaller buttons? Add .btnlg , .btnsm , or .btnxs for additional sizes.
EXAMPL E
Large button
Large button
Small button
<p>
<button
<button
</p>
<p>
<button
<button
</p>
<p>
<button
<button
</p>
<p>
<button
<button
</p>
Create block level buttonsthose that span the full w idth of a parent by adding .btnblock .
41 of 63
41 of 63
EXAMPL E
Copy
Active state
Buttons w ill appear pressed (w ith a darker background, darker border, and inset shadow ) w hen active. For
<button> elements, this is done via :active . For <a> elements, it's done w ith .active . How ever, you may use
.active on <button> s should you need to replicate the active state programmatically.
Button element
No need to add :active as it's a pseudo-class, but if you need to force the same appearance, go ahead and
add .active .
EXAMPL E
Primary button
Button
Copy
Anchor element
Add the .active class to <a> buttons.
EXAMPL E
Primary link
Link
Copy
Disabled state
Make buttons look unclickable by fading them back w ith opacity .
Button element
42 of 63
42 of 63
Copy
Cross-browser compatibility
If you add the disabled attribute to a <button> , Internet Explorer 9 and below w ill render text gray w ith
a nasty text-shadow that w e cannot fix.
Anchor element
Add the .disabled class to <a> buttons.
EXAMPL E
Copy
We use .disabled as a utility class here, similar to the common .active class, so no prefix is required.
Context-specific usage
While button classes can be used on <a> and <button> elements, only <button> elements are
supported w ithin our nav and navbar components.
Button tags
Use the button classes on an <a> , <button> , or <input> element.
43 of 63
43 of 63
EXAMPL E
Copy
Cross-browser rendering
As a best practice, w e highly recom m end using the <button> elem ent w henever possible to
ensure matching cross-brow ser rendering.
Among other things, there's a bug in Firefox <30 that prevents us from setting the lineheight of
<input> -based buttons, causing them to not exactly match the height of other buttons on Firefox.
Images
Responsive images
Images in Bootstrap 3 can be made responsive-friendly via the addition of the .imgresponsive class. This
applies maxwidth: 100%; and height: auto; to the image so that it scales nicely to the parent element.
Copy
Image shapes
Add classes to an <img> element to easily style images in any project.
Cross-browser compatibility
Keep in mind that Internet Explorer 8 lacks support for rounded corners.
44 of 63
44 of 63
EXAMPL E
Copy
Helper classes
Contextual colors
Convey meaning through color w ith a handful of emphasis utility classes. These may also be applied to links and
w ill darken on hover just like our default link styles.
EXAMPL E
Copy
class="textmuted">...</p>
class="textprimary">...</p>
class="textsuccess">...</p>
class="textinfo">...</p>
class="textwarning">...</p>
class="textdanger">...</p>
Contextual backgrounds
45 of 63
45 of 63
Similar to the contextual text color classes, easily set the background of an element to any contextual class.
Anchor components w ill darken on hover, just like the text classes.
EXAMPL E
Duis mollis, est non commodo luctus, nisi erat porttitor ligula.
Maecenas sed diam eget risus varius blandit sit amet non magna.
<p
<p
<p
<p
<p
Copy
class="bgprimary">...</p>
class="bgsuccess">...</p>
class="bginfo">...</p>
class="bgwarning">...</p>
class="bgdanger">...</p>
Close icon
Use the generic close icon for dismissing content like modals and alerts.
EXAMPL E
Copy
Carets
Use carets to indicate dropdow n functionality and direction. Note that the default caret w ill reverse automatically
in dropup menus.
EXAMPL E
Copy
46 of 63
46 of 63
<span class="caret"></span>
Quick floats
Float an element to the left or right w ith a class. !important is included to avoid specificity issues. Classes can
also be used as mixins.
<div class="pullleft">...</div>
<div class="pullright">...</div>
Copy
// Classes
.pullleft {
float: left !important;
}
.pullright {
float: right !important;
}
Copy
// Usage as mixins
.element {
.pullleft();
}
.anotherelement {
.pullright();
}
Copy
// Classes
.centerblock {
display: block;
marginleft: auto;
marginright: auto;
}
Copy
// Usage as mixins
.element {
.centerblock();
}
Clearfix
Easily clear float s by adding .clearfix to the parent elem ent. Utilizes the micro clearfix as popularized by
47 of 63
47 of 63
Copy
// Mixin itself
.clearfix() {
&:before,
&:after {
content: " ";
display: table;
}
&:after {
clear: both;
}
}
Copy
// Usage as a Mixin
.element {
.clearfix();
}
Furthermore, .invisible can be used to toggle only the visibility of an element, meaning its display is not
modified and the element can still affect the flow of the document.
Copy
<div class="show">...</div>
<div class="hidden">...</div>
Copy
48 of 63
48 of 63
// Classes
.show {
display: block !important;
}
.hidden {
display: none !important;
visibility: hidden !important;
}
.invisible {
visibility: hidden;
}
// Usage as mixins
.element {
.show();
}
.anotherelement {
.hidden();
}
Copy
// Usage as a Mixin
.skipnavigation {
.sronly();
.sronlyfocusable();
}
Copy
Image replacement
Utilize the .texthide class or mixin to help replace an element's text content w ith a background image.
<h1 class="texthide">Custom heading</h1>
Copy
// Usage as a Mixin
.heading {
.texthide();
}
Copy
Responsive utilities
For faster mobile-friendly development, use these utility classes for showing
49 of 63
49 of 63
and hiding content by device via media query. Also included are utility classes
for toggling content when printed.
Try to use these on a limited basis and avoid creating entirely different versions of the same site. Instead, use
them to complement each device's presentation.
Available classes
Use a single or combination of the available classes for toggling content across view port breakpoints.
Extra sm all devices
Sm all devices
Medium devices
Large devices
Phones (<768px)
Tablets (768px)
Desktops (992px)
Desktops (1200px)
.visiblexs*
Visible
Hidden
Hidden
Hidden
.visiblesm*
Hidden
Visible
Hidden
Hidden
.visiblemd*
Hidden
Hidden
Visible
Hidden
.visiblelg*
Hidden
Hidden
Hidden
Visible
.hiddenxs
Hidden
Visible
Visible
Visible
.hiddensm
Visible
Hidden
Visible
Visible
.hiddenmd
Visible
Visible
Hidden
Visible
.hiddenlg
Visible
Visible
Visible
Hidden
As of v3.2.0, the .visible** classes for each breakpoint come in three variations, one for each CSS
display property value listed below .
Group of classes
CSS display
.visible*block
display: block;
.visible*inline
display: inline;
.visible*inlineblock
display: inlineblock;
So, for extra small ( xs ) screens for example, the available .visible** classes are: .visiblexsblock ,
.visiblexsinline , and .visiblexsinlineblock .
The classes .visiblexs , .visiblesm , .visiblemd , and .visiblelg also exist, but are deprecated as of
v3.2.0. They are approximately equivalent to .visible*block , except w ith additional special cases for toggling
<table> -related elements.
Print classes
Similar to the regular responsive classes, use these for toggling content for print.
Classes
Brow ser
50 of 63
50 of 63
Classes
Brow ser
.visibleprintblock
Hidden
Visible
Visible
Hidden
.visibleprintinline
.visibleprintinlineblock
.hiddenprint
The class .visibleprint also exists but is deprecated as of v3.2.0. It is approximately equivalent to
.visibleprintblock , except w ith additional special cases for <table> -related elements.
Test cases
Resize your brow ser or load on different devices to test the responsive utility classes.
Visible on...
Green checkmarks indicate the element is visible in your current view port.
Extra sm all
Visible on sm all
Medium
Large
Hidden on...
Here, green checkmarks also indicate the element is hidden in your current view port.
Extra sm all
Hidden on sm all
Medium
Large
Using Less
51 of 63
51 of 63
Compiling Bootstrap
Bootstrap can be used in at least tw o w ays: w ith the compiled CSS or w ith 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 w ork w ith Bootstrap, but they are not supported by our core team.
Variables
Variables are used throughout the entire project as a w ay to centralize and share commonly used values like
colors, spacing, or font stacks. For a complete breakdow n, please see the Customizer.
Colors
Easily make use of tw o color schemes: grayscale and semantic. Grayscale colors provide quick access to
commonly used shades of black w hile semantic include various colors assigned to meaningful contextual
values.
EXAMPL E
@graydarker:
@graydark:
@gray:
@graylight:
@graylighter:
lighten(#000,
lighten(#000,
lighten(#000,
lighten(#000,
lighten(#000,
13.5%);
20%);
33.5%);
46.7%);
93.5%);
//
//
//
//
//
Copy
#222
#333
#555
#777
#eee
EXAMPL E
Copy
52 of 63
52 of 63
@brandprimary:
@brandsuccess:
@brandinfo:
@brandwarning:
@branddanger:
#428bca;
#5cb85c;
#5bc0de;
#f0ad4e;
#d9534f;
Use any of these color variables as they are or reassign them to more meaningful variables for your project.
Copy
// Use asis
.masthead {
backgroundcolor: @brandprimary;
}
// Reassigned variables in Less
@alertmessagebackground: @brandinfo;
.alert {
backgroundcolor: @alertmessagebackground;
}
Scaffolding
A handful of variables for quickly customizing key elements of your site's skeleton.
Copy
// Scaffolding
@bodybg:
#fff;
@textcolor: @black50;
Links
Easily style your links w ith the right color w ith only one value.
Copy
// Variables
@linkcolor:
@brandprimary;
@linkhovercolor: darken(@linkcolor, 15%);
// Usage
a {
color: @linkcolor;
textdecoration: none;
&:hover {
color: @linkhovercolor;
textdecoration: underline;
}
}
Note that the @linkhovercolor uses a function, another aw esome tool from Less, to automagically create the
right hover color. You can use darken , lighten , saturate , and desaturate .
Typography
Easily set your type face, text size, leading, and more w ith a few quick variables. Bootstrap makes use of these
as w ell to provide easy typographic mixins.
Copy
53 of 63
53 of 63
@fontfamilysansserif:
@fontfamilyserif:
@fontfamilymonospace:
@fontfamilybase:
@fontsizebase:
@fontsizelarge:
@fontsizesmall:
14px;
ceil((@fontsizebase * 1.25)); // ~18px
ceil((@fontsizebase * 0.85)); // ~12px
@fontsizeh1:
@fontsizeh2:
@fontsizeh3:
@fontsizeh4:
@fontsizeh5:
@fontsizeh6:
@lineheightbase:
@lineheightcomputed:
1.428571429; // 20/14
floor((@fontsizebase * @lineheightbase)); // ~20px
@headingsfontfamily:
@headingsfontweight:
@headingslineheight:
@headingscolor:
inherit;
500;
1.1;
inherit;
Icons
Tw o quick variables for customizing the location and filename of your icons.
@iconfontpath:
@iconfontname:
"../fonts/";
"glyphiconshalflingsregular";
Copy
Components
Components throughout Bootstrap make use of some default variables for setting common values. Here are the
most commonly used.
Copy
54 of 63
54 of 63
@paddingbasevertical:
@paddingbasehorizontal:
6px;
12px;
@paddinglargevertical:
@paddinglargehorizontal:
10px;
16px;
@paddingsmallvertical:
@paddingsmallhorizontal:
5px;
10px;
@paddingxsvertical:
@paddingxshorizontal:
1px;
5px;
@lineheightlarge:
@lineheightsmall:
1.33;
1.5;
@borderradiusbase:
@borderradiuslarge:
@borderradiussmall:
4px;
6px;
3px;
@componentactivecolor:
@componentactivebg:
#fff;
@brandprimary;
@caretwidthbase:
@caretwidthlarge:
4px;
5px;
Vendor mixins
Vendor mixins are mixins to help support multiple brow sers by including all relevant vendor prefixes in your
compiled CSS.
Box-sizing
Reset your components' box model w ith a single mixin. For context, see this helpful article from Mozilla.
The mixin is deprecated as of v3.2.0, w ith the introduction of autoprefixer. To preserve backw ardscompatibility, Bootstrap w ill continue to use the mixin internally until Bootstrap v4.
.boxsizing(@boxmodel) {
webkitboxsizing: @boxmodel; // Safari <= 5
mozboxsizing: @boxmodel; // Firefox <= 19
boxsizing: @boxmodel;
}
Copy
Rounded corners
Today all modern brow sers support the non-prefixed borderradius property. As such, there is no .border
radius() mixin, but Bootstrap does include shortcuts for quickly rounding tw o corners on a particular side of an
object.
Copy
55 of 63
55 of 63
.bordertopradius(@radius) {
bordertoprightradius: @radius;
bordertopleftradius: @radius;
}
.borderrightradius(@radius) {
borderbottomrightradius: @radius;
bordertoprightradius: @radius;
}
.borderbottomradius(@radius) {
borderbottomrightradius: @radius;
borderbottomleftradius: @radius;
}
.borderleftradius(@radius) {
borderbottomleftradius: @radius;
bordertopleftradius: @radius;
}
Copy
Transitions
Multiple mixins for flexibility. Set all transition information w ith one, or specify a separate delay and duration as
needed.
The mixins are deprecated as of v3.2.0, w ith the introduction of autoprefixer. To preserve backw ardscompatibility, Bootstrap w ill continue to use the mixins internally until Bootstrap v4.
Copy
56 of 63
56 of 63
.transition(@transition) {
webkittransition: @transition;
transition: @transition;
}
.transitionproperty(@transitionproperty) {
webkittransitionproperty: @transitionproperty;
transitionproperty: @transitionproperty;
}
.transitiondelay(@transitiondelay) {
webkittransitiondelay: @transitiondelay;
transitiondelay: @transitiondelay;
}
.transitionduration(@transitionduration) {
webkittransitionduration: @transitionduration;
transitionduration: @transitionduration;
}
.transitiontimingfunction(@timingfunction) {
webkittransitiontimingfunction: @timingfunction;
transitiontimingfunction: @timingfunction;
}
.transitiontransform(@transition) {
webkittransition: webkittransform @transition;
moztransition: moztransform @transition;
otransition: otransform @transition;
transition: transform @transition;
}
Transformations
Rotate, scale, translate (move), or skew any object.
The mixins are deprecated as of v3.2.0, w ith the introduction of autoprefixer. To preserve backw ardscompatibility, Bootstrap w ill continue to use the mixins internally until Bootstrap v4.
Copy
57 of 63
57 of 63
.rotate(@degrees) {
webkittransform: rotate(@degrees);
mstransform: rotate(@degrees); // IE9 only
transform: rotate(@degrees);
}
.scale(@ratio; @ratioy...) {
webkittransform: scale(@ratio, @ratioy);
mstransform: scale(@ratio, @ratioy); // IE9 only
transform: scale(@ratio, @ratioy);
}
.translate(@x; @y) {
webkittransform: translate(@x, @y);
mstransform: translate(@x, @y); // IE9 only
transform: translate(@x, @y);
}
.skew(@x; @y) {
webkittransform: skew(@x, @y);
mstransform: skewX(@x) skewY(@y); // See https://github.com/twbs/bootstrap/issues/4885;
IE9+
transform: skew(@x, @y);
}
.translate3d(@x; @y; @z) {
webkittransform: translate3d(@x, @y, @z);
transform: translate3d(@x, @y, @z);
}
.rotateX(@degrees) {
webkittransform: rotateX(@degrees);
mstransform: rotateX(@degrees); // IE9 only
transform: rotateX(@degrees);
}
.rotateY(@degrees) {
webkittransform: rotateY(@degrees);
mstransform: rotateY(@degrees); // IE9 only
transform: rotateY(@degrees);
}
.perspective(@perspective) {
webkitperspective: @perspective;
mozperspective: @perspective;
perspective: @perspective;
}
.perspectiveorigin(@perspective) {
webkitperspectiveorigin: @perspective;
mozperspectiveorigin: @perspective;
perspectiveorigin: @perspective;
}
.transformorigin(@origin) {
webkittransformorigin: @origin;
moztransformorigin: @origin;
mstransformorigin: @origin; // IE9 only
transformorigin: @origin;
}
Animations
A single mixin for using all of CSS3's animation properties in one declaration and other mixins for individual
properties.
58 of 63
58 of 63
The mixins are deprecated as of v3.2.0, w ith the introduction of autoprefixer. To preserve backw ardscompatibility, Bootstrap w ill continue to use the mixins internally until Bootstrap v4.
.animation(@animation) {
webkitanimation: @animation;
animation: @animation;
}
.animationname(@name) {
webkitanimationname: @name;
animationname: @name;
}
.animationduration(@duration) {
webkitanimationduration: @duration;
animationduration: @duration;
}
.animationtimingfunction(@timingfunction) {
webkitanimationtimingfunction: @timingfunction;
animationtimingfunction: @timingfunction;
}
.animationdelay(@delay) {
webkitanimationdelay: @delay;
animationdelay: @delay;
}
.animationiterationcount(@iterationcount) {
webkitanimationiterationcount: @iterationcount;
animationiterationcount: @iterationcount;
}
.animationdirection(@direction) {
webkitanimationdirection: @direction;
animationdirection: @direction;
}
Copy
Opacity
Set the opacity for all brow sers and provide a filter fallback for IE8.
Copy
.opacity(@opacity) {
opacity: @opacity;
// IE8 filter
@opacityie: (@opacity * 100);
filter: ~"alpha(opacity=@{opacityie})";
}
Placeholder text
Provide context for form controls w ithin each field.
.placeholder(@color: @inputcolorplaceholder) {
&::mozplaceholder
{ color: @color; } // Firefox
&:msinputplaceholder
{ color: @color; } // Internet Explorer 10+
&::webkitinputplaceholder { color: @color; } // Safari and Chrome
}
Copy
Columns
Generate columns via CSS w ithin a single element.
59 of 63
59 of 63
Gradients
Easily turn any tw o 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.
Copy
You can also specify the angle of a standard tw o-color, linear gradient:
Copy
If you need a barber-stripe style gradient, that's easy, too. Just specify a single color and w e'll overlay a
translucent w hite stripe.
Copy
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 w ith these mixins:
#gradient > .verticalthreecolors(#777; #333; 25%; #000);
#gradient > .horizontalthreecolors(#777; #333; 25%; #000);
Copy
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 .resetfilter() mixin alongside backgroundimage: none; .
Utility mixins
Utility mixins are mixins that combine otherw ise unrelated CSS properties to achieve a specific goal or task.
Clearfix
Forget adding class="clearfix" to any element and instead add the .clearfix() mixin w here appropriate.
Uses the micro clearfix from Nicolas Gallager.
Copy
60 of 63
60 of 63
// Mixin
.clearfix() {
&:before,
&:after {
content: " ";
display: table;
}
&:after {
clear: both;
}
}
// Usage
.container {
.clearfix();
}
Horizontal centering
Quickly center any element w ithin its parent. Requires width or maxwidth to be set.
Copy
// Mixin
.centerblock() {
display: block;
marginleft: auto;
marginright: auto;
}
// Usage
.container {
width: 940px;
.centerblock();
}
Sizing helpers
Specify the dimensions of an object more easily.
Copy
// Mixins
.size(@width; @height) {
width: @width;
height: @height;
}
.square(@size) {
.size(@size; @size);
}
// Usage
.image { .size(400px; 300px); }
.avatar { .square(48px); }
Resizable textareas
Easily configure the resize options for any textarea, or any other element. Defaults to normal brow ser behavior
( both ).
61 of 63
61 of 63
.resizable(@direction: both) {
// Options: horizontal, vertical, both
resize: @direction;
// Safari fix
overflow: auto;
}
Truncating text
Easily truncate text w ith an ellipsis w ith a single mixin. Requires elem ent to be block or inlineblock
level.
Copy
// Mixin
.textoverflow() {
overflow: hidden;
textoverflow: ellipsis;
whitespace: nowrap;
}
// Usage
.branchname {
display: inlineblock;
maxwidth: 200px;
.textoverflow();
}
Retina images
Specify tw o image paths and the @1x image dimensions, and Bootstrap w ill provide an @2x media query. If
you have m any im ages to serve, consider w riting your retina im age CSS m anually in a single
m edia query.
.imgretina(@file1x; @file2x; @width1x; @height1x) {
backgroundimage: url("@{file1x}");
@media
only screen and (webkitmindevicepixelratio:
only screen and ( minmozdevicepixelratio:
only screen and (
omindevicepixelratio:
only screen and (
mindevicepixelratio:
only screen and (
minresolution:
only screen and (
minresolution:
backgroundimage: url("@{file2x}");
backgroundsize: @width1x @height1x;
}
Copy
2),
2),
2/1),
2),
192dpi),
2dppx) {
}
// Usage
.jumbotron {
.imgretina("/img/bg1x.png", "/img/bg2x.png", 100px, 100px);
}
62 of 63
62 of 63
Using Sass
While Bootstrap is built on Less, it also has an official Sass port. We maintain
it in a separate GitHub repository and handle updates with a conversion script.
What's included
Since the Sass port has a separate repo and serves a slightly different audience, the contents of the project
differ greatly from the main Bootstrap project. This ensures the Sass port is as compatible w ith as many
Sass-based systems as possible.
Path
Description
lib/
tasks/
test/
Compilation tests
templates/
vendor/assets/
Rakefile
Visit the Sass port's GitHub repository to see these files in action.
Installation
For information on how to install and use Bootstrap for Sass, consult the GitHub repository readme. It's the most
up to date source and includes information for use w ith Rails, Compass, and standard Sass projects.
63 of 63
63 of 63