The default grid system provided as part of Bootstrap is a 940px-wide, 12-column grid.
It also has four responsive variations for various devices and resolutions: phone, tablet portrait, table landscape and small desktops, and large widescreen desktops.
<div class="row"> <div class="span4">...</div> <div class="span8">...</div> </div>
As shown here, a basic layout can be created with two "columns," each spanning a number of the 12 foundational columns we defined as part of our grid system.
<div class="row"> <div class="span4">...</div> <div class="span4 offset4">...</div> </div>
With the static (non-fluid) grid system in Bootstrap, nesting is easy. To nest your content, just add a new .row
and set of .span*
columns within an existing .span*
column.
Nested rows should include a set of columns that add up to the number of columns of it's parent. For example, two nested .span3
columns should be placed within a .span6
.
<div class="row"> <div class="span12"> Level 1 of column <div class="row"> <div class="span6">Level 2</div> <div class="span6">Level 2</div> </div> </div> </div>
The fluid grid system uses percents for column widths instead of fixed pixels. It also has the same responsive variations as our fixed grid system, ensuring proper proportions for key screen resolutions and devices.
Make any row fluid simply by changing .row
to .row-fluid
. The columns stay the exact same, making it super straightforward to flip between fixed and fluid layouts.
<div class="row-fluid"> <div class="span4">...</div> <div class="span8">...</div> </div>
Nesting with fluid grids is a bit different: the number of nested columns doesn't need to match the parent. Instead, your columns are reset at each level because each row takes up 100% of the parent column.
<div class="row-fluid"> <div class="span12"> Level 1 of column <div class="row-fluid"> <div class="span6">Level 2</div> <div class="span6">Level 2</div> </div> </div> </div>
Variable | Default value | Description |
---|---|---|
@gridColumns |
12 | Number of columns |
@gridColumnWidth |
60px | Width of each column |
@gridGutterWidth |
20px | Negative space between columns |
@siteWidth |
Computed sum of all columns and gutters | Counts number of columns and gutters to set width of the .container-fixed() mixin |
Built into Bootstrap are a handful of variables for customizing the default 940px grid system, documented above. All variables for the grid are stored in variables.less.
Modifying the grid means changing the three @grid*
variables and recompiling Bootstrap. Change the grid variables in variables.less and use one of the four ways documented to recompile. If you're adding more columns, be sure to add the CSS for those in grid.less.
Customization of the grid only works at the default level, the 940px grid. To maintain the responsive aspects of Bootstrap, you'll also have to customize the grids in responsive.less.
The default and simple 940px-wide, centered layout for just about any website or page provided by a single <div class="container">
.
<body> <div class="container"> ... </div> </body>
<div class="container-fluid">
gives flexible page structure, min- and max-widths, and a left-hand sidebar. It's great for apps and docs.
<div class="container-fluid"> <div class="row-fluid"> <div class="span2"> <!--Sidebar content--> </div> <div class="span10"> <!--Body content--> </div> </div> </div>
Media queries allow for custom CSS based on a number of conditions—ratios, widths, display type, etc—but usually focuses around min-width
and max-width
.
Use media queries responsibly and only as a start to your mobile audiences. For larger projects, do consider dedicated code bases and not layers of media queries.
Bootstrap supports a handful of media queries in a single file to help make your projects more appropriate on different devices and screen resolutions. Here's what's included:
Label | Layout width | Column width | Gutter width |
---|---|---|---|
Smartphones | 480px and below | Fluid columns, no fixed widths | |
Smartphones to tablets | 767px and below | Fluid columns, no fixed widths | |
Portrait tablets | 768px and above | 42px | 20px |
Default | 980px and up | 60px | 20px |
Large display | 1200px and up | 70px | 30px |
To ensure devices display responsive pages properly, include the viewport meta tag.
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Bootstrap doesn't automatically include these media queries, but understanding and adding them is very easy and requires minimal setup. You have a few options for including the responsive features of Bootstrap:
Why not just include it? Truth be told, not everything needs to be responsive. Instead of encouraging developers to remove this feature, we figure it best to enable it.
// Landscape phones and down @media (max-width: 480px) { ... } // Landscape phone to portrait tablet @media (max-width: 768px) { ... } // Portrait tablet to landscape and desktop @media (min-width: 768px) and (max-width: 980px) { ... } // Large desktop @media (min-width: 1200px) { .. }
For faster mobile-friendly development, use these basic utility classes for showing and hidding content by device.
Use on a limited basis and avoid creating entirely different versions of the same site. Instead, use them to complement each device's presentation.
For example, you might show a <select>
element for nav on mobile layouts, but not on tablets or desktops.
Shown here is a table of the classes we support and their effect on a given media query layout (labeled by device). They can be found in responsive.less
.
Class | Phones 480px and below | Tablets 767px and below | Desktops 768px and above |
---|---|---|---|
.visible-phone |
Visible | Hidden | Hidden |
.visible-tablet |
Hidden | Visible | Hidden |
.visible-desktop |
Hidden | Hidden | Visible |
.hidden-phone |
Hidden | Visible | Visible |
.hidden-tablet |
Visible | Hidden | Visible |
.hidden-desktop |
Visible | Visible | Hidden |
Resize your browser or load on different devices to test the above clases.
Find out what's happening, right now, with the people and organizations you care about.