Twitter Bootstrap

Bootstrap is a toolkit from Twitter designed to kickstart development of webapps and sites.
It includes base CSS and HTML for typography, forms, buttons, tables, grids, navigation, and more.

Nerd alert: Bootstrap is built with Less and was designed to work out of the gate with only modern browsers in mind.

Hotlink the CSS

For the quickest and easiest start, just copy this snippet into your webpage.

Use it with Less

A fan of using Less? No problem, just clone the repo and add these lines:

Fork on GitHub

Download, fork, pull, file issues, and more with the official Bootstrap repo on Github.

Bootstrap on GitHub »

default grid

The default grid system provided as part of Bootstrap is a 940px wide 16-column grid. It's a flavor of the popular 960 grid system, but without the additional margin/padding on the left and right sides.

Example grid markup

As shown here, a basic layout can be created with two "columns," each spanning a number of the 16 foundational columns we defined as part of our grid system. See the examples below for more variations.

  1. <div class = "row" >
  2. <div class = "span6 columns" >
  3. ...
  4. </div>
  5. <div class = "span10 columns" >
  6. ...
  7. </div>
  8. </div>
one
one
one
one
one
one
one
one
one
one
one
one
one
one
one
one
2
2
2
2
2
2
2
2
3
3
3
3
3
one
four
four
four
four
four
6
6
eight
eight
5
eleven
16

offset columns

four
8 offset 4
4 offset 4
4 offset 4
5 offset 3
5 offset 3
10 offset 6

fixed layout

A basic 940px wide, centered container layout for just about any site or page.

  1. <body>
  2. <div class = "container" >
  3. ...
  4. </div>
  5. </body>

fluid layout

A flexible fluid or liquid page structure with min- and max-widths and a left-hand sidebar. Great for apps.

  1. <body>
  2. <div class = "container-fluid" >
  3. <div class = "sidebar" >
  4. ...
  5. </div>
  6. <divclass = " content" >
  7. ...
  8. </div>
  9. </div>
  10. </body>

Headings and copy

A standard typographic hierarchy for structuring your webpages.

h1. heading 1

h2. Heading 2

h3. heading 3

h4. heading 4

h5. heading 5
h6. heading 6

example paragraph

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 ut id elit.

Example heading Has sub-heading...

You can also add subheadings with the <strong>and<em>

misc. elements

Using emphasis, addresses, & abbreviations

<strong> <em> <address> <abbr>

When to use

Emphasis tags ( <strong>and <em>) should be used to add visual distinction between a word or phrase and its surrounding copy. Use <strong>for plain old attention and <em>for slick attention and titles.

Emphasis in a paragraph

Fusce dapibus , tellus ac cursus commodo , tortor mauris condimentum nibh , ut fermentum massa justo sit ametrisus. Maecenas faucibus mollis interdum. Nulla vitae elit libero, a pharetra augue.

Addresses

The addresselement is used for—you guessed it!—addresses. Here's how it looks:

Twitter Inc.
795 Folsom Ave, Suite 600
San Francisco, CA 94107
P: (123) 456-7890

Note: Each line in an addressmust end with a line-break ( <br />) to properly structure the content as it is read in real life without any styles applied.

Abbreviations

For abbreviations and acronyms, use the abbrtag ( acronymis deprecated in HTML5 ). Put the shorthand form within the tag and set a title for the complete name.

Blockquotes

<blockquote> <p> <cite>

Be sure to wrap your blockquotearound paragraphand citetags. When citing a source, use the citeelement. The CSS will automatically preface a name with an em dash (—).

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua...

Dr. Julius Hibbert

Lists

Unordered<ul>

  • Jeremy Bixby
  • Robert Dezure
  • Josh Washington
  • Anton Capresi
  • My Team Mates
    • George Castanza
    • Jerry Seinfeld
    • Cosmo Kramer
    • Elaine Bennis
    • Newman
  • John Jacob
  • Paul Pierce
  • Kevin Garnett

unstyled<ul.unstyled>

  • Jeremy Bixby
  • Robert Dezure
  • Josh Washington
  • Anton Capresi
  • My Team Mates
    • George Castanza
    • Jerry Seinfeld
    • Cosmo Kramer
    • Elaine Bennis
    • Newman
  • John Jacob
  • Paul Pierce
  • Kevin Garnett

ordered<ol>

  1. Jeremy Bixby
  2. Robert Dezure
  3. Josh Washington
  4. Anton Capresi
  5. My Team Mates
    1. George Castanza
    2. Jerry Seinfeld
    3. Cosmo Kramer
    4. Elaine Bennis
    5. Newman
  6. John Jacob
  7. Paul Pierce
  8. Kevin Garnett

Descriptiondl

Description lists
A description list is perfect for defining terms.
Euismod
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.

building tables

<table> <thead> <tbody> <tr> <th> <td> <colspan> <caption>

Tables are great—for a lot of things. Great tables, however, need a bit of markup love to be useful, scalable, and readable (at the code level). Here are a few tips to help.

Always wrap your column headers in a theadsuch that hierarchy is thead> tr> th.

Similar to the column headers, all your table's body content should be wrapped in a tbodyso your hierarchy is tbody> tr> td.

Example: Default table styles

All tables will be automatically styled with only the essential borders to ensure readability and maintain structure. No need to add extra classes or attributes.

# first name last name language
one Some One English
2 Joe six pack English
3 Stu Dent Code
  1. <table class = "common-table" >
  2. ...
  3. </table>

Example: Zebra striped

Get a little fancy with your tables by adding zebra-striping—just add the .zebra-stripedclass.

# first name last name language
one Some One English
2 Joe six pack English
3 Stu Dent Code
  1. <table class = "common-table zebra-striped" >
  2. ...
  3. </table>

Example: Zebra-striped w/ TableSorter.js

Taking the previous example, we improve the usefulness of our tables by providing sorting functionality via jQuery and the Tablesorter plugin. Click any column's header to change the sort.

# first name last name language
one Your One English
2 Joe six pack English
3 Stu Dent Code
  1. <script type = "text/javascript" src = "js/jquery/jquery.tablesorter.min.js" ></script>
  2. <script type = "text/javascript" >
  3. $ ( document ). ready ( function () {
  4. $ ( "table#sortTableExample" ). tablesorter ( { sortList : [[ 1 , 0 ]]} );
  5. });
  6. </script>
  7. <table class = "common-table zebra-striped" >
  8. ...
  9. </table>

default styles

All forms are given default styles to present them in a readable and scalable way. Styles are provided for text inputs, select lists, textareas, radio buttons and checkboxes, and buttons.

Example form legend
Some Value Here
Small snippet of help text
Example form legend
@
Example form legend
Note: Labels surround all the options for much larger click areas and a more usable form.
to All times are shown as Pacific Standard Time (GMT -08:00).
Block of help text to describe the field above if need be.

stacked forms

Add .form-stackedto your form's HTML and you'll have labels on top of their fields instead of to their left. This works great if your forms are short or you have two columns of inputs for heavy forms.

Example form legend
Example form legend
Note: Labels surround all the options for much larger click areas and a more usable form.

Buttons

As a convention, buttons are used for actions while links are used for objects. For instance, "Download" could be a button and "recent activity" could be a link.

All buttons default to a light gray style, but a blue .primaryclass is available. Plus, rolling your own styles is easy peasy.

Example buttons

Button styles can be applied to anything with the .btnapplied. Typically you'll want to apply these to only a, button, and select inputelements. Here's how it looks:

Alternate sizes

Fancy larger or smaller buttons? Have at it!

disabled state

For buttons that are not active or are disabled by the app for one reason or another, use the disabled state. That's .disabledfor links and :disabledfor buttonelements.

Links

Buttons

Basic alerts

One-line messages for highlighting the failure, possible failure, or success of an action. Particularly useful for forms.

×

Oh snap! Change this and that and try again.

×

Holy gaucamole! Best check yo self, you're not looking too good.

×

Well done! You successfully read this alert message.

×

Head up! This is an alert that needs your attention, but it's not a huge priority just yet.

block messages

For messages that require a bit of explanation, we have paragraph style alerts. These are perfect for bubbling up longer error messages, warning a user of a pending action, or just presenting information for more emphasis on the page.

×

Oh snap! You got an error!Change this and that and try again. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Cras mattis consectetur purus sit amet fermentum.

Take this action Or do this

×

Holy gaucamole! This is a warning!Best check yo self, you're not looking too good. Nulla vitae elit libero, a pharetra augue. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

Take this action Or do this

×

Well done!You successfully read this alert message. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Maecenas faucibus mollis interdum.

Take this action Or do this

×

Head up!This is an alert that needs your attention, but it's not a huge priority just yet.

Take this action Or do this

Modals

Modals—dialogs or lightboxes—are great for contextual actions in situations where it's important that the background context be maintained.

Tool Tips

Twipsies are super useful for aiding a confused user and pointing them in the right direction.

Lorem ipsum dolar sit amet illo error ipsum veritatis aut iste perspiciatis iste voluptas natus illo quasi odit aut natus consequuntur consequuntur, aut natus illo voluptatem odit perspiciatis laudantium rem doloremque totam voluptas. Voluptasdicta eaque beatae aperiam ut enim voluptatem explicabo explicabo, voluptas quia odit fugit accusantium totam totam architecto explicabo sit quasi fugit fugit, totam doloremque unde sunt sed dicta quae accusantium fugit voluptas nemo voluptas voluptatem rem quae aut vertitas quasi.

below!
right!
left!
above!

Popovers

Use popovers to provide subtextual information to a page without effecting layout.

Popover Title

Etiam porta sem malesuada magna mollis euismod. Maecenas faucibus mollis interdum. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.

Bootstrap was built with Preboot , an open-source pack of mixins and variables to be used in conjunction with Less , a CSS preprocessor for faster and easier web development.

Check out how we used Preboot in Bootstrap and how you can make use of it should you choose to run Less on your next project.

How to use it

Use this option to make full use of Bootstrap's Less variables, mixins, and nesting in CSS via javascript in your browser.

  1. <link rel = "stylesheet/less" type = "text/css" href = "less/bootstrap.less" media = "all" />
  2. <script type = "text/javascript" src = "js/less-1.0.41.min.js" ></script>

Not feeling the .js solution? Try the Less Mac app or use Node.js to compile when you deploy your code.

What's included

Here are some of the highlights of what's included in Twitter Bootstrap as part of Bootstrap. Head over to the Bootstrap website or Github project page to download and learn more.

color variables

Variables in Less are perfect for maintaining and updating your CSS headache free. When you want to change a color value or a frequently used value, update it in one spot and you're set.

  1. // links
  2. @linkColor : #8b59c2;
  3. @linkColorHover : darken ( @linkColor , 10 );
  4.  
  5. // Grays
  6. @black : #000;
  7. @grayDark : lighten ( @black , 25 %);
  8. @gray : lighten ( @black , 50 %);
  9. @grayLight : lighten ( @black , 70 %);
  10. @grayLighter : lighten ( @black , 90 %);
  11. @white : #fff;
  12.  
  13. // Accent Colors
  14. @blue : #08b5fb;
  15. @green : #46a546;
  16. @red : #9d261d;
  17. @yellow : #ffc40d;
  18. @orange : #f89406;
  19. @pink : #c3325f;
  20. @purple : #7a43b6;
  21.  
  22. // baseline
  23. @baseline : 20px ;

Commenting

Less also provides another style of commenting in addition to CSS's normal /* ... */syntax.

  1. // This is a comment
  2. /* This is also a comment */

Mixins up the wazoo

Mixins are basically includes or partials for CSS, allowing you to combine a block of code into one. They're great for vendor prefixed properties like box-shadow, cross-browser gradients, font stacks, and more. Below is a sample of the mixins that are included with Bootstrap.

Font stacks

  1. #font {
  2. . shorthand ( @weight : normal , @size : 14px , @lineHeight : 20px ) {
  3. font - size : @size ;
  4. font - weight : @weight ;
  5. line - height : @lineHeight ;
  6. }
  7. . sans - serif ( @weight : normal , @size : 14px , @lineHeight : 20px ) {
  8. font - family : "Helvetica Neue" , ​​Helvetica , Arial , sans - serif ;
  9. font - size : @size ;
  10. font - weight : @weight ;
  11. line - height : @lineHeight ;
  12. }
  13. . serif ( @weight : normal , @size : 14px , @lineHeight : 20px ) {
  14. font - family : "Georgia" , Times New Roman , Times , sans - serif ;
  15. font - size : @size ;
  16. font - weight : @weight ;
  17. line - height : @lineHeight ;
  18. }
  19. . monospace ( @weight : normal , @size : 12px , @lineHeight : 20px ) {
  20. font - family : "Monaco" , Courier New , monospace ;
  21. font - size : @size ;
  22. font - weight : @weight ;
  23. line - height : @lineHeight ;
  24. }
  25. }

Gradients

  1. #gradient {
  2. . horizontal ( @startColor : #555, @endColor: #333) {
  3. background - color : @endColor ;
  4. background - repeat : repeat - x ;
  5. background - image : - khtml - gradient ( linear , left top , right top , from ( @startColor ), to ( @endColor )); // Konqueror
  6. background - image : - moz - linear - gradient ( left , @startColor , @endColor ); //FF 3.6+
  7. background - image : - ms - linear - gradient ( left , @startColor , @endColor ); // IE10
  8. background - image : - webkit - gradient ( linear , left top , right top , color - stop ( 0 %, @startColor ), color - stop ( 100 %, @endColor )); // Safari 4+, Chrome 2+
  9. background - image : - webkit - linear - gradient ( left , @startColor , @endColor ); // Safari 5.1+, Chrome 10+
  10. background - image : - o - linear - gradient ( left , @startColor , @endColor ); // Opera 11.10
  11. - ms - filter : %( "progid:DXImageTransform.Microsoft.gradient(startColorstr='%d', endColorstr='%d', GradientType=1)" , @startColor , @endColor ); // IE8+
  12. filter : e (%( "progid:DXImageTransform.Microsoft.gradient(startColorstr='%d', endColorstr='%d', GradientType=1)" , @startColor , @endColor )); // IE6 & IE7
  13. background - image : linear - gradient ( left , @startColor , @endColor ); // Le standard
  14. }
  15. . vertical ( @startColor : #555, @endColor: #333) {
  16. background - color : @endColor ;
  17. background - repeat : repeat - x ;
  18. background - image : - khtml - gradient ( linear , left top , left bottom , from ( @startColor ), to ( @endColor )); // Konqueror
  19. background - image : - moz - linear - gradient ( @startColor , @endColor ); //FF 3.6+
  20. background - image : - ms - linear - gradient ( @startColor , @endColor ); // IE10
  21. background - image : - webkit - gradient ( linear , left top , left bottom , color - stop ( 0 %, @startColor ), color - stop ( 100 %, @endColor )); // Safari 4+, Chrome 2+
  22. background - image : - webkit - linear - gradient ( @startColor , @endColor ); // Safari 5.1+, Chrome 10+
  23. background - image : - o - linear - gradient ( @startColor , @endColor ); // Opera 11.10
  24. - ms - filter : %( "progid:DXImageTransform.Microsoft.gradient(startColorstr='%d', endColorstr='%d', GradientType=0)" , @startColor , @endColor ); // IE8+
  25. filter : e (%( "progid:DXImageTransform.Microsoft.gradient(startColorstr='%d', endColorstr='%d', GradientType=0)" , @startColor , @endColor )); // IE6 & IE7
  26. background - image : linear - gradient ( @startColor , @endColor ); // The standard
  27. }
  28. . directional ( @startColor : #555, @endColor: #333, @deg: 45deg) {
  29. ...
  30. }
  31. . vertical - three - colors ( @startColor : #00b3ee, @midColor: #7a43b6, @colorStop: 0.5, @endColor: #c3325f) {
  32. ...
  33. }
  34. }

Operations and grid system

Get fancy and perform some math to generate flexible and powerful mixins like the one below.

  1. // grid
  2. @gridColumns : 16 ;
  3. @gridColumnWidth : 40px ;
  4. @gridGutterWidth : 20px ;
  5.  
  6. // Grid System
  7. . container {
  8. width : @siteWidth ;
  9. margin : 0 auto ;
  10. . clearfix ();
  11. }
  12. . columns ( @columnSpan : 1 ) {
  13. display : inline _
  14. float : left ;
  15. width : ( @gridColumnWidth * @columnSpan ) + ( @gridGutterWidth * ( @columnSpan - 1 ));
  16. margin - left : @gridGutterWidth ;
  17. &: first - child {
  18. margin - left : 0 ;
  19. }
  20. }
  21. . offset ( @columnOffset : 1 ) {
  22. margin - left : ( @gridColumnWidth * @columnOffset ) + ( @gridGutterWidth * ( @columnOffset - 1 )) ! important ;
  23. }