Containers
Containers are the most basic layout element and are required when using our default grid system. Choose from a responsive, fixed-width container (meaning its max-width changes at each breakpoint) or fluid-width (meaning it’s 100% wide all the time).
While containers can be nested, most layouts do not require a nested container.
<div class="container"> <!-- Content here --> </div>
Use .container-fluid for a full width container, spanning the entire width of the viewport.
<div class="container-fluid"> ... </div>
Responsive breakpoints
Since Bootstrap is developed to be mobile first, we use a handful of media queries to create sensible breakpoints for our layouts and interfaces. These breakpoints are mostly based on minimum viewport widths and allow us to scale up elements as the viewport changes.
Bootstrap primarily uses the following media query ranges—or breakpoints—in our source Sass files for our layout, grid system, and components.
// Extra small devices (portrait phones, less than 576px)
// No media query since this is the default in Bootstrap
// Small devices (landscape phones, 576px and up)
@media (min-width: 576px) { ... }
// Medium devices (tablets, 768px and up)
@media (min-width: 768px) { ... }
// Large devices (desktops, 992px and up)
@media (min-width: 992px) { ... }
// Extra large devices (large desktops, 1280px and up)
@media (min-width: 1280px) { ... }
Since we write our source CSS in Sass, all our media queries are available via Sass function:
.some-class {
@media(min-width: breakpoint-min(md)) {
display: block;
}
}
We occasionally use media queries that go in the other direction (the given screen size or smaller):
// Extra small devices (portrait phones, less than 576px)
@media (max-width: 575px) { ... }
// Small devices (landscape phones, less than 768px)
@media (max-width: 767px) { ... }
// Medium devices (tablets, less than 992px)
@media (max-width: 991px) { ... }
// Large devices (desktops, less than 1200px)
@media (max-width: 1199px) { ... }
// Extra large devices (large desktops)
// No media query since the extra-large breakpoint has no upper bound on its width
Once again, these media queries are also available via Sass function:
.some-class {
@media(min-width: breakpoint-max(md)) {
...
}
}
There are also media queries in Sass mixins:
@include media-breakpoint-up(xl) { ... }
@include media-breakpoint-down(lg) { ... }
@include media-breakpoint-only(xl) { ... }
@include media-breakpoint-between(md, xl) { ... }
Grid
Bootstrap’s grid system uses a series of containers, rows, and columns to layout and align content. It’s built with flexbox and is fully responsive. Below is an example and an in-depth look at how the grid comes together.
New to or unfamiliar with flexbox? Read this CSS Tricks flexbox guide for background, terminology, guidelines, and code snippets.
<div class="container"> <div class="row"> <div class="col-sm"> One of three columns </div> <div class="col-sm"> One of three columns </div> <div class="col-sm"> One of three columns </div> </div> </div>
The above example creates three equal-width columns on small, medium, large, and extra large devices using our predefined grid classes. Those columns are centered in the page with the parent .container.
Breaking it down, here’s how it works:
- Containers provide a means to center and horizontally pad your site’s contents. Use
.containerfor a responsive pixel width or.container-fluidforwidth: 100%across all viewport and device sizes. - Rows are wrappers for columns. Each column has horizontal
padding(called a gutter) for controlling the space between them. Thispaddingis then counteracted on the rows with negative margins. This way, all the content in your columns is visually aligned down the left side. - In a grid layout, content must be placed within columns and only columns may be immediate children of rows.
- Thanks to flexbox, grid columns without a specified
widthwill automatically layout as equal width columns. For example, four instances of.col-smwill each automatically be 25% wide from the small breakpoint and up. See the auto-layout columns section for more examples. - Column classes indicate the number of columns you’d like to use out of the possible 12 per row. So, if you want three equal-width columns across, you can use
.col-4. - Column
widths are set in percentages, so they’re always fluid and sized relative to their parent element. - Columns have horizontal
paddingto create the gutters between individual columns, however, you can remove themarginfrom rows andpaddingfrom columns with.no-gutterson the.row. - To make the grid responsive, there are five grid breakpoints, one for each responsive breakpoint: all breakpoints (extra small), small, medium, large, and extra large.
- Grid breakpoints are based on minimum width media queries, meaning they apply to that one breakpoint and all those above it (e.g.,
.col-sm-4applies to small, medium, large, and extra large devices, but not the firstxsbreakpoint). - You can use predefined grid classes (like
.col-4) or Sass mixins for more semantic markup.
Be aware of the limitations and bugs around flexbox, like the inability to use some HTML elements as flex containers.
Grid options
While Bootstrap uses ems or rems for defining most sizes, pxs are used for grid breakpoints and container widths. This is because the viewport width is in pixels and does not change with the font size.
See how aspects of the Bootstrap grid system work across multiple devices with a handy table.
|
Extra small <576px |
Small ≥576px |
Medium ≥768px |
Large ≥992px |
Extra large ≥1200px |
|
|---|---|---|---|---|---|
| Max container width | None (auto) | 540px | 720px | 960px | 1140px |
| Class prefix | .col- |
.col-sm- |
.col-md- |
.col-lg- |
.col-xl- |
| # of columns | 12 | ||||
| Gutter width | 30px (15px on each side of a column) | ||||
| Nestable | Yes | ||||
| Column ordering | Yes | ||||
Auto-layout columns
Utilize breakpoint-specific column classes for easy column sizing without an explicit numbered class like .col-sm-6.
Equal-width
For example, here are two grid layouts that apply to every device and viewport, from xs to xl. Add any number of unit-less classes for each breakpoint you need and every column will be the same width.
<div class="container"> <div class="row"> <div class="col"> 1 of 2 </div> <div class="col"> 2 of 2 </div> </div> <div class="row"> <div class="col"> 1 of 3 </div> <div class="col"> 2 of 3 </div> <div class="col"> 3 of 3 </div> </div> </div>
Equal-width columns can be broken into multiple lines, but there was a Safari flexbox bug that prevented this from working without an explicit flex-basis or border. There are workarounds for older browser versions, but they shouldn’t be necessary if you’re up-to-date.
<div class="container"> <div class="row"> <div class="col">Column</div> <div class="col">Column</div> <div class="w-100"></div> <div class="col">Column</div> <div class="col">Column</div> </div> </div>
Setting one column width
Auto-layout for flexbox grid columns also means you can set the width of one column and have the sibling columns automatically resize around it. You may use predefined grid classes (as shown below), grid mixins, or inline widths. Note that the other columns will resize no matter the width of the center column.
<div class="container"> <div class="row"> <div class="col"> 1 of 3 </div> <div class="col-12"> 2 of 3 (wider) </div> <div class="col"> 3 of 3 </div> </div> <div class="row"> <div class="col"> 1 of 3 </div> <div class="col-10"> 2 of 3 (wider) </div> <div class="col"> 3 of 3 </div> </div> </div>
Variable width content
Use col-{breakpoint}-auto classes to size columns based on the natural width of their content.
<div class="container"> <div class="row justify-content-md-center"> <div class="col col-lg-2"> 1 of 3 </div> <div class="col-md-auto"> Variable width content </div> <div class="col col-lg-2"> 3 of 3 </div> </div> <div class="row"> <div class="col"> 1 of 3 </div> <div class="col-md-auto"> Variable width content </div> <div class="col col-lg-2"> 3 of 3 </div> </div> </div>
Equal-width multi-row
Create equal-width columns that span multiple rows by inserting a .w-100 where you want the columns to break to a new line. Make the breaks responsive by mixing the .w-100 with some responsive display utilities.
<div class="row"> <div class="col">.col</div> <div class="col">.col</div> <div class="w-100"></div> <div class="col">.col</div> <div class="col">.col</div> </div>
Responsive classes
Bootstrap’s grid includes five tiers of predefined classes for building complex responsive layouts. Customize the size of your columns on extra small, small, medium, large, or extra large devices however you see fit.
All breakpoints
For grids that are the same from the smallest of devices to the largest, use the .col and .col-* classes. Specify a numbered class when you need a particularly sized column; otherwise, feel free to stick to .col.
<div class="row"> <div class="col">.col</div> <div class="col">.col</div> <div class="col">.col</div> <div class="col">.col</div> </div> <div class="row"> <div class="col-16">.col-16</div> <div class="col-8">.col-8</div> </div>
Stacked to horizontal
Using a single set of .col-sm-* classes, you can create a basic grid system that starts out stacked before becoming horizontal with at the small breakpoint (sm).
<div class="row"> <div class="col-sm-8">.col-sm-16</div> <div class="col-sm-4">.col-sm-8</div> </div> <div class="row"> <div class="col-sm">.col-sm</div> <div class="col-sm">.col-sm</div> <div class="col-sm">.col-sm</div> </div>
Mix and match
Don’t want your columns to simply stack in some grid tiers? Use a combination of different classes for each tier as needed. See the example below for a better idea of how it all works.
<!-- Stack the columns on mobile by making one full-width and the other half-width --> <div class="row"> <div class="col-24 col-md-16">.col-12 .col-md-16</div> <div class="col-12 col-md-8">.col-12 .col-md-8</div> </div> <!-- Columns start at 50% wide on mobile and bump up to 33.3% wide on desktop --> <div class="row"> <div class="col-12 col-md-8">.col-12 .col-md-8</div> <div class="col-12 col-md-8">.col-12 .col-md-8</div> <div class="col-12 col-md-8">.col-12 .col-md-8</div> </div> <!-- Columns are always 50% wide, on mobile and desktop --> <div class="row"> <div class="col-12">.col-12</div> <div class="col-12">.col-12</div> </div>
Alignment
Use flexbox alignment utilities to vertically and horizontally align columns.
Vertical alignment
<div class="container"> <div class="row align-items-start"> <div class="col"> One of three columns </div> <div class="col"> One of three columns </div> <div class="col"> One of three columns </div> </div> <div class="row align-items-center"> <div class="col"> One of three columns </div> <div class="col"> One of three columns </div> <div class="col"> One of three columns </div> </div> <div class="row align-items-end"> <div class="col"> One of three columns </div> <div class="col"> One of three columns </div> <div class="col"> One of three columns </div> </div> </div>
<div class="container"> <div class="row"> <div class="col align-self-start"> One of three columns </div> <div class="col align-self-center"> One of three columns </div> <div class="col align-self-end"> One of three columns </div> </div> </div>
Horizontal alignment
<div class="container"> <div class="row justify-content-start"> <div class="col-8"> One of two columns </div> <div class="col-8"> One of two columns </div> </div> <div class="row justify-content-center"> <div class="col-8"> One of two columns </div> <div class="col-8"> One of two columns </div> </div> <div class="row justify-content-end"> <div class="col-8"> One of two columns </div> <div class="col-8"> One of two columns </div> </div> <div class="row justify-content-around"> <div class="col-8"> One of two columns </div> <div class="col-8"> One of two columns </div> </div> <div class="row justify-content-between"> <div class="col-8"> One of two columns </div> <div class="col-8"> One of two columns </div> </div> </div>
No gutters
The gutters between columns in our predefined grid classes can be removed with .no-gutters. This removes the negative margins from .row and the horizontal padding from all immediate children columns.
Here’s the source code for creating these styles. Note that column overrides are scoped to only the first children columns and are targeted via attribute selector. While this generates a more specific selector, column padding can still be further customized with spacing utilities.
Need an edge-to-edge design? Drop the parent .container or .container-fluid.
.no-gutters {
margin-right: 0;
margin-left: 0;
> .col,
> [class*="col-"] {
padding-right: 0;
padding-left: 0;
}
}
In practice, here’s how it looks. Note you can continue to use this with all other predefined grid classes (including column widths, responsive tiers, reorders, and more).
<div class="row no-gutters"> <div class="col-24 col-sm-12 col-md-16">.col-24 .col-sm-12 .col-md-16</div> <div class="col-12 col-md-8">.col-12 .col-md-8</div> </div>
Line gutters
Line gutters has the same usege as no-gutters, so class is added to row. This removes default gutter spacing from all immediate children columns and add 1px margin-top and 1px padding-left.
.line-gutters {
margin: -1px 0 0 -1px;
& > .col,
& > [class*="col-"] {
margin-bottom: 0;
margin-top: 1px;
padding-left: 1px;
padding-right: 0;
}
}
<div class="row line-gutters">
<div class="col-24 col-sm-12 col-md-6">.col-24 .col-sm-12 .col-md-6</div>
<div class="col-24 col-sm-12 col-md-6">.col-24 .col-sm-12 .col-md-6</div>
<div class="col-12 col-md-6">.col-12 .col-md-6</div>
<div class="col-12 col-md-6">.col-12 .col-md-6</div>
</div>
Column wrapping
If more than 12 columns are placed within a single row, each group of extra columns will, as one unit, wrap onto a new line.
Since 18 + 8 = 26 > 24, this 8-column-wide div gets wrapped onto a new line as one contiguous unit.
Subsequent columns continue along the new line.
<div class="row"> <div class="col-18">.col-18</div> <div class="col-8">.col-8<br>Since 18 + 8 = 26 > 24, this 8-column-wide div gets wrapped onto a new line as one contiguous unit.</div> <div class="col-12">.col-12<br>Subsequent columns continue along the new line.</div> </div>
Column breaks
Breaking columns to a new line in flexbox requires a small hack: add an element with width: 100% wherever you want to wrap your columns to a new line. Normally this is accomplished with multiple .rows, but not every implementation method can account for this.
<div class="row"> <div class="col-12 col-sm-6">.col-12 .col-sm-6</div> <div class="col-12 col-sm-6">.col-12 .col-sm-6</div> <!-- Force next columns to break to new line --> <div class="w-100"></div> <div class="col-12 col-sm-6">.col-12 .col-sm-6</div> <div class="col-12 col-sm-6">.col-12 .col-sm-6</div> </div>
You may also apply this break at specific breakpoints with our responsive display utilities.
<div class="row"> <div class="col-12 col-sm-8">.col-12 .col-sm-8</div> <div class="col-12 col-sm-8">.col-12 .col-sm-8</div> <!-- Force next columns to break to new line at md breakpoint and up --> <div class="w-100 d-none d-md-block"></div> <div class="col-12 col-sm-8">.col-12 .col-sm-8</div> <div class="col-12 col-sm-8">.col-12 .col-sm-8</div> </div>
Reordering
Reordering Order classes
Use .order- classes for controlling the visual order of your content. These classes are responsive, so you can set the order by breakpoint (e.g., .order-1.order-md-2). Includes support for 1 through 24 across all five grid tiers.
<div class="container"> <div class="row"> <div class="col"> First, but unordered </div> <div class="col order-12"> Second, but last </div> <div class="col order-1"> Third, but first </div> </div> </div>
There are also responsive .order-first and .order-last classes that change the order of an element by applying order: -1 and order: 13 (order: $columns + 1), respectively. These classes can also be intermixed with the numbered .order-* classes as needed.
Offsetting columns
You can offset grid columns in two ways: our responsive .offset- grid classes and our margin utilities. Grid classes are sized to match columns while margins are more useful for quick layouts where the width of the offset is variable.
Offset classes
Move columns to the right using .offset-md-* classes. These classes increase the left margin of a column by * columns. For example, .offset-md-8 moves .col-md-8 over four columns.
<div class="row"> <div class="col-md-8">.col-md-8</div> <div class="col-md-8 offset-md-8">.col-md-8 .offset-md-8</div> </div> <div class="row"> <div class="col-md-6 offset-md-6">.col-md-6 .offset-md-6</div> <div class="col-md-6 offset-md-6">.col-md-6 .offset-md-6</div> </div> <div class="row"> <div class="col-md-12 offset-md-6">.col-md-12 .offset-md-6</div> </div>
In addition to column clearing at responsive breakpoints, you may need to reset offsets. See this in action in the grid example.
<div class="row"> <div class="col-sm-10 col-md-12">.col-sm-10 .col-md-12</div> <div class="col-sm-10 offset-sm-4 col-md-12 offset-md-0">.col-sm-10 .offset-sm-4 .col-md-12 .offset-md-0</div> </div> <div class="row"> <div class="col-sm-12 col-md-10 col-lg-12">.col-sm-12 .col-md-10 .col-lg-12</div> <div class="col-sm-12 col-md-10 offset-md-4 col-lg-12 offset-lg-0">.col-sm-12 .col-md-10 .offset-md-4 .col-lg-12 .offset-lg-0</div> </div>
Margin utilities
With the move to flexbox in v4, you can use margin utilities like .mr-auto to force sibling columns away from one another.
<div class="row"> <div class="col-md-8">.col-md-8</div> <div class="col-md-8 ml-auto">.col-md-8 .ml-auto</div> </div> <div class="row"> <div class="col-md-6 ml-md-auto">.col-md-6 .ml-md-auto</div> <div class="col-md-6 ml-md-auto">.col-md-6 .ml-md-auto</div> </div> <div class="row"> <div class="col-auto mr-auto">.col-auto .mr-auto</div> <div class="col-auto">.col-auto</div> </div>
Nesting
To nest your content with the default grid, add a new .row and set of .col-sm-* columns within an existing .col-sm-* column. Nested rows should include a set of columns that add up to 12 or fewer (it is not required that you use all 12 available columns).
<div class="row"> <div class="col-sm-18"> Level 1: .col-sm-18 <div class="row"> <div class="col-16 col-sm-12"> Level 2: .col-16 .col-sm-12 </div> <div class="col-8 col-sm-12"> Level 2: .col-8 .col-sm-12 </div> </div> </div> </div>
Sass mixins
When using Bootstrap’s source Sass files, you have the option of using Sass variables and mixins to create custom, semantic, and responsive page layouts. Our predefined grid classes use these same variables and mixins to provide a whole suite of ready-to-use classes for fast responsive layouts.
Variables
Variables and maps determine the number of columns, the gutter width, and the media query point at which to begin floating columns. We use these to generate the predefined grid classes documented above, as well as for the custom mixins listed below.
$grid-columns: 12; $grid-gutter-width: 30px; $grid-breakpoints: ( // Extra small screen / phone xs: 0, // Small screen / phone sm: 576px, // Medium screen / tablet md: 768px, // Large screen / desktop lg: 992px, // Extra large screen / wide desktop xl: 1200px ); $container-max-widths: ( sm: 540px, md: 720px, lg: 960px, xl: 1140px );
Mixins
Mixins are used in conjunction with the grid variables to generate semantic CSS for individual grid columns.
// Creates a wrapper for a series of columns @include make-row(); // Make the element grid-ready (applying everything but the width) @include make-col-ready(); @include make-col($size, $columns: $grid-columns); // Get fancy by offsetting, or changing the sort order @include make-col-offset($size, $columns: $grid-columns);
Example usage
You can modify the variables to your own custom values, or just use the mixins with their default values. Here’s an example of using the default settings to create a two-column layout with a gap between.
.example-container {
width: 800px;
@include make-container();
}
.example-row {
@include make-row();
}
.example-content-main {
@include make-col-ready();
@include media-breakpoint-up(sm) {
@include make-col(6);
}
@include media-breakpoint-up(lg) {
@include make-col(8);
}
}
.example-content-secondary {
@include make-col-ready();
@include media-breakpoint-up(sm) {
@include make-col(6);
}
@include media-breakpoint-up(lg) {
@include make-col(4);
}
}
<div class="example-container"> <div class="example-row"> <div class="example-content-main">Main content</div> <div class="example-content-secondary">Secondary content</div> </div> </div>
Customizing the grid
Using our built-in grid Sass variables and maps, it’s possible to completely customize the predefined grid classes. Change the number of tiers, the media query dimensions, and the container widths—then recompile.
Columns and gutters
The number of grid columns can be modified via Sass variables. $grid-columns is used to generate the widths (in percent) of each individual column while $grid-gutter-width allows breakpoint-specific widths that are divided evenly across padding-left and padding-right for the column gutters.
$grid-columns: 12 !default; $grid-gutter-width: 30px !default;
Grid tiers
Moving beyond the columns themselves, you may also customize the number of grid tiers. If you wanted just four grid tiers, you’d update the $grid-breakpoints and $container-max-widths to something like this:
$grid-breakpoints: ( xs: 0, sm: 480px, md: 768px, lg: 1024px ); $container-max-widths: ( sm: 420px, md: 720px, lg: 960px );
When making any changes to the Sass variables or maps, you’ll need to save your changes and recompile. Doing so will output a brand new set of predefined grid classes for column widths, offsets, and ordering. Responsive visibility utilities will also be updated to use the custom breakpoints. Make sure to set grid values in px (not rem, em, or %).
<p><strong>Containers</strong></p>
<p>Containers are the most basic layout element and are <strong>required when using our default grid system</strong>. Choose from a responsive, fixed-width container (meaning its <code>max-width</code> changes at each breakpoint) or fluid-width (meaning it’s <code>100%</code> wide all the time).</p>
<p>While containers can be nested, most layouts do not require a nested container.</p>
<div class="mdl-example">
<div class="container a-max-width-sm">
<div class="row">
<div class="col-18"><div style="background-color: #957bbe; border-radius: 4px; height: 125px"></div></div>
<div class="col-6"><div style="background-color: #80bdff; border-radius: 4px; height: 125px"></div></div>
</div>
</div>
<pre><div class="container">
<!-- Content here -->
</div></pre>
</div>
<p>Use .container-fluid for a full width container, spanning the entire width of the viewport.</p>
<div class="mdl-example">
<div class="container-fluid">
<div class="row">
<div class="col-18"><div style="background-color: #957bbe; border-radius: 4px; height: 125px"></div></div>
<div class="col-6"><div style="background-color: #80bdff; border-radius: 4px; height: 125px"></div></div>
</div>
</div>
<pre><div class="container-fluid">
...
</div></pre>
</div>
<p><strong>Responsive breakpoints</strong></p>
<p>Since Bootstrap is developed to be mobile first, we use a handful of <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries" target="_blank">media queries</a> to create sensible breakpoints for our layouts and interfaces. These breakpoints are mostly based on minimum viewport widths and allow us to scale up elements as the viewport changes.</p>
<p>Bootstrap primarily uses the following media query ranges—or breakpoints—in our source Sass files for our layout, grid system, and components.</p>
<pre class="mdl-code">
// Extra small devices (portrait phones, less than 576px)
// No media query since this is the default in Bootstrap
// Small devices (landscape phones, 576px and up)
@media (min-width: 576px) { ... }
// Medium devices (tablets, 768px and up)
@media (min-width: 768px) { ... }
// Large devices (desktops, 992px and up)
@media (min-width: 992px) { ... }
// Extra large devices (large desktops, 1280px and up)
@media (min-width: 1280px) { ... }
</pre>
<p>Since we write our source CSS in Sass, all our media queries are available via Sass function:</p>
<pre class="mdl-code">
.some-class {
@media(min-width: breakpoint-min(md)) {
display: block;
}
}
</pre>
<p>We occasionally use media queries that go in the other direction (the given screen size <em>or smaller</em>):</p>
<pre class="mdl-code">
// Extra small devices (portrait phones, less than 576px)
@media (max-width: 575px) { ... }
// Small devices (landscape phones, less than 768px)
@media (max-width: 767px) { ... }
// Medium devices (tablets, less than 992px)
@media (max-width: 991px) { ... }
// Large devices (desktops, less than 1200px)
@media (max-width: 1199px) { ... }
// Extra large devices (large desktops)
// No media query since the extra-large breakpoint has no upper bound on its width
</pre>
<p>Once again, these media queries are also available via Sass function:</p>
<pre class="mdl-code">
.some-class {
@media(min-width: breakpoint-max(md)) {
...
}
}
</pre>
<p>There are also media queries in Sass mixins:</p>
<pre class="mdl-code">
@include media-breakpoint-up(xl) { ... }
@include media-breakpoint-down(lg) { ... }
@include media-breakpoint-only(xl) { ... }
@include media-breakpoint-between(md, xl) { ... }
</pre>
<p><strong>Grid</strong></p>
<p>Bootstrap’s grid system uses a series of containers, rows, and columns to layout and align content. It’s built with <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Using_CSS_flexible_boxes">flexbox</a> and is fully responsive. Below is an example and an in-depth look at how the grid comes together.</p>
<p><strong>New to or unfamiliar with flexbox?</strong> <a href="https://css-tricks.com/snippets/css/a-guide-to-flexbox/#flexbox-background">Read this CSS Tricks flexbox guide</a> for background, terminology, guidelines, and code snippets.</p>
<div class="mdl-example">
<div class="mdl-example-inner">
<div class="container">
<div class="row">
<div class="col-sm">
<div class="p-1 mdl-highlight">One of three columns</div>
</div>
<div class="col-sm">
<div class="p-1 mdl-highlight">One of three columns</div>
</div>
<div class="col-sm">
<div class="p-1 mdl-highlight">One of three columns</div>
</div>
</div>
</div>
</div>
<pre><div class="container">
<div class="row">
<div class="col-sm">
One of three columns
</div>
<div class="col-sm">
One of three columns
</div>
<div class="col-sm">
One of three columns
</div>
</div>
</div></pre>
</div>
<p>The above example creates three equal-width columns on small, medium, large, and extra large devices using our predefined grid classes. Those columns are centered in the page with the parent <code>.container</code>.</p>
<p>Breaking it down, here’s how it works:</p>
<ul>
<li>Containers provide a means to center and horizontally pad your site’s contents. Use <code>.container</code> for a responsive pixel width or <code>.container-fluid</code> for <code>width: 100%</code> across all viewport and device sizes.</li>
<li>Rows are wrappers for columns. Each column has horizontal <code>padding</code> (called a gutter) for controlling the space between them. This <code>padding</code> is then counteracted on the rows with negative margins. This way, all the content in your columns is visually aligned down the left side.</li>
<li>In a grid layout, content must be placed within columns and only columns may be immediate children of rows.</li>
<li>Thanks to flexbox, grid columns without a specified <code>width</code> will automatically layout as equal width columns. For example, four instances of <code>.col-sm</code> will each automatically be 25% wide from the small breakpoint and up. See the auto-layout columns section for more examples.</li>
<li>Column classes indicate the number of columns you’d like to use out of the possible 12 per row. So, if you want three equal-width columns across, you can use <code>.col-4</code>.</li>
<li>Column <code>width</code>s are set in percentages, so they’re always fluid and sized relative to their parent element.</li>
<li>Columns have horizontal <code>padding</code> to create the gutters between individual columns, however, you can remove the <code>margin</code> from rows and <code>padding</code> from columns with <code>.no-gutters</code> on the <code>.row</code>.</li>
<li>To make the grid responsive, there are five grid breakpoints, one for each responsive breakpoint: all breakpoints (extra small), small, medium, large, and extra large.</li>
<li>Grid breakpoints are based on minimum width media queries, meaning <strong>they apply to that one breakpoint and all those above it</strong> (e.g., <code>.col-sm-4</code> applies to small, medium, large, and extra large devices, but not the first <code>xs</code> breakpoint).</li>
<li>You can use predefined grid classes (like <code>.col-4</code>) or Sass mixins for more semantic markup.</li>
</ul>
<p>Be aware of the limitations and <a href="https://github.com/philipwalton/flexbugs">bugs around flexbox</a>, like the <a href="https://github.com/philipwalton/flexbugs#9-some-html-elements-cant-be-flex-containers">inability to use some HTML elements as flex containers</a>.</p>
<p><strong>Grid options</strong></p>
<p>While Bootstrap uses <code>em</code>s or <code>rem</code>s for defining most sizes, <code>px</code>s are used for grid breakpoints and container widths. This is because the viewport width is in pixels and does not change with the <a href="https://drafts.csswg.org/mediaqueries-3/#units">font size</a>.</p>
<p>See how aspects of the Bootstrap grid system work across multiple devices with a handy table.</p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th></th>
<th class="text-center">
Extra small<br>
<small><576px</small>
</th>
<th class="text-center">
Small<br>
<small>≥576px</small>
</th>
<th class="text-center">
Medium<br>
<small>≥768px</small>
</th>
<th class="text-center">
Large<br>
<small>≥992px</small>
</th>
<th class="text-center">
Extra large<br>
<small>≥1200px</small>
</th>
</tr>
</thead>
<tbody>
<tr>
<th class="text-nowrap" scope="row">Max container width</th>
<td>None (auto)</td>
<td>540px</td>
<td>720px</td>
<td>960px</td>
<td>1140px</td>
</tr>
<tr>
<th class="text-nowrap" scope="row">Class prefix</th>
<td><code>.col-</code></td>
<td><code>.col-sm-</code></td>
<td><code>.col-md-</code></td>
<td><code>.col-lg-</code></td>
<td><code>.col-xl-</code></td>
</tr>
<tr>
<th class="text-nowrap" scope="row"># of columns</th>
<td colspan="5">12</td>
</tr>
<tr>
<th class="text-nowrap" scope="row">Gutter width</th>
<td colspan="5">30px (15px on each side of a column)</td>
</tr>
<tr>
<th class="text-nowrap" scope="row">Nestable</th>
<td colspan="5">Yes</td>
</tr>
<tr>
<th class="text-nowrap" scope="row">Column ordering</th>
<td colspan="5">Yes</td>
</tr>
</tbody>
</table>
<p><strong>Auto-layout columns</strong></p>
<p>Utilize breakpoint-specific column classes for easy column sizing without an explicit numbered class like <code>.col-sm-6</code>.</p>
<p>Equal-width</p>
<p>For example, here are two grid layouts that apply to every device and viewport, from <code>xs</code> to <code>xl</code>. Add any number of unit-less classes for each breakpoint you need and every column will be the same width.</p>
<div class="mdl-example">
<div class="mdl-example-inner">
<div class="container">
<div class="row">
<div class="col">
<div class="p-1 mdl-highlight">1 of 2</div>
</div>
<div class="col">
<div class="p-1 mdl-highlight">2 of 2</div>
</div>
</div>
<div class="row">
<div class="col">
<div class="p-1 mdl-highlight">1 of 3</div>
</div>
<div class="col">
<div class="p-1 mdl-highlight">2 of 3</div>
</div>
<div class="col">
<div class="p-1 mdl-highlight">3 of 3</div>
</div>
</div>
</div>
</div>
<pre><div class="container">
<div class="row">
<div class="col">
1 of 2
</div>
<div class="col">
2 of 2
</div>
</div>
<div class="row">
<div class="col">
1 of 3
</div>
<div class="col">
2 of 3
</div>
<div class="col">
3 of 3
</div>
</div>
</div></pre>
</div>
<p>Equal-width columns can be broken into multiple lines, but there was a <a href="https://github.com/philipwalton/flexbugs#11-min-and-max-size-declarations-are-ignored-when-wrapping-flex-items">Safari flexbox bug</a> that prevented this from working without an explicit <code>flex-basis</code> or <code>border</code>. There are workarounds for older browser versions, but they shouldn’t be necessary if you’re up-to-date.</p>
<div class="mdl-example">
<div class="mdl-example-inner">
<div class="container">
<div class="row">
<div class="col">
<div class="p-1 mdl-highlight">Column</div>
</div>
<div class="col">
<div class="p-1 mdl-highlight">Column</div>
</div>
<div class="w-100">
</div>
<div class="col">
<div class="p-1 mdl-highlight">Column</div>
</div>
<div class="col">
<div class="p-1 mdl-highlight">Column</div>
</div>
</div>
</div>
</div>
<pre><div class="container">
<div class="row">
<div class="col">Column</div>
<div class="col">Column</div>
<div class="w-100"></div>
<div class="col">Column</div>
<div class="col">Column</div>
</div>
</div></pre>
</div>
<p><strong>Setting one column width</strong></p>
<p>Auto-layout for flexbox grid columns also means you can set the width of one column and have the sibling columns automatically resize around it. You may use predefined grid classes (as shown below), grid mixins, or inline widths. Note that the other columns will resize no matter the width of the center column.</p>
<div class="mdl-example">
<div class="mdl-example-inner">
<div class="container">
<div class="row">
<div class="col">
<div class="p-1 mdl-highlight">1 of 3</div>
</div>
<div class="col-12">
<div class="p-1 mdl-highlight">2 of 3 (wider)</div>
</div>
<div class="col">
<div class="p-1 mdl-highlight">3 of 3</div>
</div>
</div>
<div class="row">
<div class="col">
<div class="p-1 mdl-highlight">1 of 3</div>
</div>
<div class="col-10">
<div class="p-1 mdl-highlight">2 of 3 (wider)</div>
</div>
<div class="col">
<div class="p-1 mdl-highlight">3 of 3</div>
</div>
</div>
</div>
</div>
<pre><div class="container">
<div class="row">
<div class="col">
1 of 3
</div>
<div class="col-12">
2 of 3 (wider)
</div>
<div class="col">
3 of 3
</div>
</div>
<div class="row">
<div class="col">
1 of 3
</div>
<div class="col-10">
2 of 3 (wider)
</div>
<div class="col">
3 of 3
</div>
</div>
</div></pre>
</div>
<p><strong>Variable width content</strong></p>
<p n:syntax="off">Use <code>col-{breakpoint}-auto</code> classes to size columns based on the natural width of their content.</p>
<div class="mdl-example">
<div class="mdl-example-inner">
<div class="container">
<div class="row justify-content-md-center">
<div class="col col-lg-4">
<div class="p-1 mdl-highlight">1 of 3</div>
</div>
<div class="col-md-auto">
<div class="p-1 mdl-highlight">Variable width content</div>
</div>
<div class="col col-lg-4">
<div class="p-1 mdl-highlight">3 of 3</div>
</div>
</div>
<div class="row">
<div class="col">
<div class="p-1 mdl-highlight">1 of 3</div>
</div>
<div class="col-md-auto">
<div class="p-1 mdl-highlight">Variable width content</div>
</div>
<div class="col col-lg-4">
<div class="p-1 mdl-highlight">3 of 3</div>
</div>
</div>
</div>
</div>
<pre><div class="container">
<div class="row justify-content-md-center">
<div class="col col-lg-2">
1 of 3
</div>
<div class="col-md-auto">
Variable width content
</div>
<div class="col col-lg-2">
3 of 3
</div>
</div>
<div class="row">
<div class="col">
1 of 3
</div>
<div class="col-md-auto">
Variable width content
</div>
<div class="col col-lg-2">
3 of 3
</div>
</div>
</div></pre>
</div>
<p><strong>Equal-width multi-row</strong></p>
<p>Create equal-width columns that span multiple rows by inserting a <code>.w-100</code> where you want the columns to break to a new line. Make the breaks responsive by mixing the <code>.w-100</code> with some responsive display utilities.</p>
<div class="mdl-example">
<div class="mdl-example-inner">
<div class="row">
<div class="col"><div class="p-1 mdl-highlight">.col</div></div>
<div class="col"><div class="p-1 mdl-highlight">.col</div></div>
<div class="w-100"></div>
<div class="col"><div class="p-1 mdl-highlight">.col</div></div>
<div class="col"><div class="p-1 mdl-highlight">.col</div></div>
</div>
</div>
<pre><div class="row">
<div class="col">.col</div>
<div class="col">.col</div>
<div class="w-100"></div>
<div class="col">.col</div>
<div class="col">.col</div>
</div></pre>
</div>
<p><strong>Responsive classes</strong></p>
<p>Bootstrap’s grid includes five tiers of predefined classes for building complex responsive layouts. Customize the size of your columns on extra small, small, medium, large, or extra large devices however you see fit.</p>
<p><strong>All breakpoints</strong></p>
<p>For grids that are the same from the smallest of devices to the largest, use the <code>.col</code> and <code>.col-*</code> classes. Specify a numbered class when you need a particularly sized column; otherwise, feel free to stick to <code>.col</code>.</p>
<div class="mdl-example">
<div class="mdl-example-inner">
<div class="row">
<div class="col"><div class="p-1 mdl-highlight">.col</div></div>
<div class="col"><div class="p-1 mdl-highlight">.col</div></div>
<div class="col"><div class="p-1 mdl-highlight">.col</div></div>
<div class="col"><div class="p-1 mdl-highlight">.col</div></div>
</div>
<div class="row">
<div class="col-16"><div class="p-1 mdl-highlight">.col-16</div></div>
<div class="col-8"><div class="p-1 mdl-highlight">.col-8</div></div>
</div>
</div>
<pre><div class="row">
<div class="col">.col</div>
<div class="col">.col</div>
<div class="col">.col</div>
<div class="col">.col</div>
</div>
<div class="row">
<div class="col-16">.col-16</div>
<div class="col-8">.col-8</div>
</div></pre>
</div>
<p><strong>Stacked to horizontal</strong></p>
<p>Using a single set of <code>.col-sm-*</code> classes, you can create a basic grid system that starts out stacked before becoming horizontal with at the small breakpoint (<code>sm</code>).</p>
<div class="mdl-example">
<div class="mdl-example-inner">
<div class="row">
<div class="col-sm-16"><div class="p-1 mdl-highlight">.col-sm-16</div></div>
<div class="col-sm-8"><div class="p-1 mdl-highlight">.col-sm-8</div></div>
</div>
<div class="row">
<div class="col-sm"><div class="p-1 mdl-highlight">.col-sm</div></div>
<div class="col-sm"><div class="p-1 mdl-highlight">.col-sm</div></div>
<div class="col-sm"><div class="p-1 mdl-highlight">.col-sm</div></div>
</div>
</div>
<pre><div class="row">
<div class="col-sm-8">.col-sm-16</div>
<div class="col-sm-4">.col-sm-8</div>
</div>
<div class="row">
<div class="col-sm">.col-sm</div>
<div class="col-sm">.col-sm</div>
<div class="col-sm">.col-sm</div>
</div></pre>
</div>
<p><strong>Mix and match</strong></p>
<p>Don’t want your columns to simply stack in some grid tiers? Use a combination of different classes for each tier as needed. See the example below for a better idea of how it all works.</p>
<div class="mdl-example">
<div class="mdl-example-inner">
<div class="row">
<div class="col-24 col-md-16"><div class="p-1 mdl-highlight">.col-24 .col-md-16</div></div>
<div class="col-12 col-md-8"><div class="p-1 mdl-highlight">.col-12 .col-md-8</div></div>
</div>
<div class="row">
<div class="col-12 col-md-8"><div class="p-1 mdl-highlight">.col-12 .col-md-8</div></div>
<div class="col-12 col-md-8"><div class="p-1 mdl-highlight">.col-12 .col-md-8</div></div>
<div class="col-12 col-md-8"><div class="p-1 mdl-highlight">.col-12 .col-md-8</div></div>
</div>
<div class="row">
<div class="col-12"><div class="p-1 mdl-highlight">.col-12</div></div>
<div class="col-12"><div class="p-1 mdl-highlight">.col-12</div></div>
</div>
</div>
<pre><!-- Stack the columns on mobile by making one full-width and the other half-width -->
<div class="row">
<div class="col-24 col-md-16">.col-12 .col-md-16</div>
<div class="col-12 col-md-8">.col-12 .col-md-8</div>
</div>
<!-- Columns start at 50% wide on mobile and bump up to 33.3% wide on desktop -->
<div class="row">
<div class="col-12 col-md-8">.col-12 .col-md-8</div>
<div class="col-12 col-md-8">.col-12 .col-md-8</div>
<div class="col-12 col-md-8">.col-12 .col-md-8</div>
</div>
<!-- Columns are always 50% wide, on mobile and desktop -->
<div class="row">
<div class="col-12">.col-12</div>
<div class="col-12">.col-12</div>
</div></pre>
</div>
<p><strong>Alignment</strong></p>
<p>Use flexbox alignment utilities to vertically and horizontally align columns.</p>
<p><strong>Vertical alignment</strong></p>
<div class="mdl-example">
<div class="mdl-example-inner">
<div class="container">
<div class="row noalign-items-start no-gutters mdl-highlight" style="height: 200px">
<div class="col m-0">
<div class="p-1 mdl-highlight">One of three columns</div>
</div>
<div class="col m-0">
<div class="p-1 mdl-highlight">One of three columns</div>
</div>
<div class="col m-0">
<div class="p-1 mdl-highlight">One of three columns</div>
</div>
</div>
<div class="row align-items-center no-gutters mdl-highlight" style="height: 200px">
<div class="col m-0">
<div class="p-1 mdl-highlight">One of three columns</div>
</div>
<div class="col m-0">
<div class="p-1 mdl-highlight">One of three columns</div>
</div>
<div class="col m-0">
<div class="p-1 mdl-highlight">One of three columns</div>
</div>
</div>
<div class="row align-items-end no-gutters mdl-highlight" style="height: 200px">
<div class="col m-0">
<div class="p-1 mdl-highlight">One of three columns</div>
</div>
<div class="col m-0">
<div class="p-1 mdl-highlight">One of three columns</div>
</div>
<div class="col m-0">
<div class="p-1 mdl-highlight">One of three columns</div>
</div>
</div>
</div>
</div>
<pre><div class="container">
<div class="row align-items-start">
<div class="col">
One of three columns
</div>
<div class="col">
One of three columns
</div>
<div class="col">
One of three columns
</div>
</div>
<div class="row align-items-center">
<div class="col">
One of three columns
</div>
<div class="col">
One of three columns
</div>
<div class="col">
One of three columns
</div>
</div>
<div class="row align-items-end">
<div class="col">
One of three columns
</div>
<div class="col">
One of three columns
</div>
<div class="col">
One of three columns
</div>
</div>
</div></pre>
</div>
<p></p>
<div class="mdl-example">
<div class="mdl-example-inner">
<div class="container">
<div class="row no-gutters mdl-highlight" style="height: 150px">
<div class="col align-self-start m-0">
<div class="p-1 mdl-highlight">One of three columns</div>
</div>
<div class="col align-self-center m-0">
<div class="p-1 mdl-highlight">One of three columns</div>
</div>
<div class="col align-self-end m-0">
<div class="p-1 mdl-highlight">One of three columns</div>
</div>
</div>
</div>
</div>
<pre><div class="container">
<div class="row">
<div class="col align-self-start">
One of three columns
</div>
<div class="col align-self-center">
One of three columns
</div>
<div class="col align-self-end">
One of three columns
</div>
</div>
</div></pre>
</div>
<p><strong>Horizontal alignment</strong></p>
<div class="mdl-example">
<div class="container">
<div class="row justify-content-start">
<div class="col-8">
<div class="p-1 mdl-highlight">One of two columns</div>
</div>
<div class="col-8">
<div class="p-1 mdl-highlight">One of two columns</div>
</div>
</div>
<div class="row justify-content-center">
<div class="col-8">
<div class="p-1 mdl-highlight">One of two columns</div>
</div>
<div class="col-8">
<div class="p-1 mdl-highlight">One of two columns</div>
</div>
</div>
<div class="row justify-content-end">
<div class="col-8">
<div class="p-1 mdl-highlight">One of two columns</div>
</div>
<div class="col-8">
<div class="p-1 mdl-highlight">One of two columns</div>
</div>
</div>
<div class="row justify-content-around">
<div class="col-8">
<div class="p-1 mdl-highlight">One of two columns</div>
</div>
<div class="col-8">
<div class="p-1 mdl-highlight">One of two columns</div>
</div>
</div>
<div class="row justify-content-between">
<div class="col-8">
<div class="p-1 mdl-highlight">One of two columns</div>
</div>
<div class="col-8">
<div class="p-1 mdl-highlight">One of two columns</div>
</div>
</div>
</div>
<pre><div class="container">
<div class="row justify-content-start">
<div class="col-8">
One of two columns
</div>
<div class="col-8">
One of two columns
</div>
</div>
<div class="row justify-content-center">
<div class="col-8">
One of two columns
</div>
<div class="col-8">
One of two columns
</div>
</div>
<div class="row justify-content-end">
<div class="col-8">
One of two columns
</div>
<div class="col-8">
One of two columns
</div>
</div>
<div class="row justify-content-around">
<div class="col-8">
One of two columns
</div>
<div class="col-8">
One of two columns
</div>
</div>
<div class="row justify-content-between">
<div class="col-8">
One of two columns
</div>
<div class="col-8">
One of two columns
</div>
</div>
</div></pre>
</div>
<p><strong>No gutters</strong></p>
<p>The gutters between columns in our predefined grid classes can be removed with <code>.no-gutters</code>. This removes the negative <code>margins</code> from <code>.row</code> and the horizontal <code>padding</code> from all immediate children columns.</p>
<p>Here’s the source code for creating these styles. Note that column overrides are scoped to only the first children columns and are targeted via <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors">attribute selector</a>. While this generates a more specific selector, column padding can still be further customized with spacing utilities.</p>
<p><strong>Need an edge-to-edge design?</strong> Drop the parent <code>.container</code> or <code>.container-fluid</code>.</p>
<pre class="mdl-code">
.no-gutters {
margin-right: 0;
margin-left: 0;
> .col,
> [class*="col-"] {
padding-right: 0;
padding-left: 0;
}
}
</pre>
<p>In practice, here’s how it looks. Note you can continue to use this with all other predefined grid classes (including column widths, responsive tiers, reorders, and more).</p>
<div class="mdl-example">
<div class="mdl-example-inner">
<div class="row no-gutters">
<div class="col-24 col-sm-12 col-md-16">
<div class="p-1 mdl-highlight">.col-24 .col-sm-12 .col-md-16</div>
</div>
<div class="col-12 col-md-8">
<div class="p-1 mdl-highlight">.col-12 .col-md-8</div>
</div>
</div>
</div>
<pre><div class="row no-gutters">
<div class="col-24 col-sm-12 col-md-16">.col-24 .col-sm-12 .col-md-16</div>
<div class="col-12 col-md-8">.col-12 .col-md-8</div>
</div></pre>
</div>
<p><strong>Line gutters</strong></p>
<p>Line gutters has the same usege as no-gutters, so class is added to row. This removes default gutter spacing from all immediate children columns and <strong>add</strong> 1px margin-top and 1px padding-left.</p>
<pre class="mdl-code">
.line-gutters {
margin: -1px 0 0 -1px;
& > .col,
& > [class*="col-"] {
margin-bottom: 0;
margin-top: 1px;
padding-left: 1px;
padding-right: 0;
}
}
</pre>
<p></p>
<div class="mdl-example">
<div class="mdl-example-inner">
<div class="row line-gutters">
<div class="col-24 col-sm-12 col-md-6">
<div class="p-1 mdl-highlight">.col-24 .col-sm-12 .col-md-6</div>
</div>
<div class="col-24 col-sm-12 col-md-6">
<div class="p-1 mdl-highlight">.col-24 .col-sm-12 .col-md-6</div>
</div>
<div class="col-12 col-md-6">
<div class="p-1 mdl-highlight">.col-12 .col-md-6</div>
</div>
<div class="col-12 col-md-6">
<div class="p-1 mdl-highlight">.col-12 .col-md-6</div>
</div>
</div>
</div>
<pre><div class="row line-gutters">
<div class="col-24 col-sm-12 col-md-6">.col-24 .col-sm-12 .col-md-6</div>
<div class="col-24 col-sm-12 col-md-6">.col-24 .col-sm-12 .col-md-6</div>
<div class="col-12 col-md-6">.col-12 .col-md-6</div>
<div class="col-12 col-md-6">.col-12 .col-md-6</div>
</div></pre>
</div>
<p><strong>Column wrapping</strong></p>
<p>If more than 12 columns are placed within a single row, each group of extra columns will, as one unit, wrap onto a new line.</p>
<div class="mdl-example">
<div class="mdl-example-inner">
<div class="row">
<div class="col-18"><div class="p-1 mdl-highlight">.col-18</div></div>
<div class="col-8"><div class="p-1 mdl-highlight">.col-8<br>Since 18 + 8 = 26 > 24, this 8-column-wide div gets wrapped onto a new line as one contiguous unit.</div></div>
<div class="col-12"><div class="p-1 mdl-highlight">.col-12<br>Subsequent columns continue along the new line.</div></div>
</div>
</div>
<pre>
<div class="row">
<div class="col-18">.col-18</div>
<div class="col-8">.col-8<br>Since 18 + 8 = 26 > 24, this 8-column-wide div gets wrapped onto a new line as one contiguous unit.</div>
<div class="col-12">.col-12<br>Subsequent columns continue along the new line.</div>
</div></pre>
</div>
<p><strong>Column breaks</strong></p>
<p>Breaking columns to a new line in flexbox requires a small hack: add an element with <code>width: 100%</code> wherever you want to wrap your columns to a new line. Normally this is accomplished with multiple <code>.rows</code>, but not every implementation method can account for this.</p>
<div class="mdl-example">
<div class="mdl-example-inner">
<div class="row">
<div class="col-12 col-sm-9"><div class="p-1 mdl-highlight">.col-12 .col-sm-6</div></div>
<div class="col-12 col-sm-9"><div class="p-1 mdl-highlight">.col-12 .col-sm-6</div></div>
<div class="w-100"></div>
<div class="col-12 col-sm-6"><div class="p-1 mdl-highlight">.col-12 .col-sm-6</div></div>
<div class="col-12 col-sm-6"><div class="p-1 mdl-highlight">.col-12 .col-sm-6</div></div>
</div>
</div>
<pre><div class="row">
<div class="col-12 col-sm-6">.col-12 .col-sm-6</div>
<div class="col-12 col-sm-6">.col-12 .col-sm-6</div>
<!-- Force next columns to break to new line -->
<div class="w-100"></div>
<div class="col-12 col-sm-6">.col-12 .col-sm-6</div>
<div class="col-12 col-sm-6">.col-12 .col-sm-6</div>
</div></pre>
</div>
<p>You may also apply this break at specific breakpoints with our responsive display utilities.</p>
<div class="mdl-example">
<div class="mdl-example-inner">
<div class="row">
<div class="col-12 col-sm-8"><div class="p-1 mdl-highlight">.col-12 .col-sm-8</div></div>
<div class="col-12 col-sm-8"><div class="p-1 mdl-highlight">.col-12 .col-sm-8</div></div>
<div class="w-100 d-none d-md-block"></div>
<div class="col-12 col-sm-8"><div class="p-1 mdl-highlight">.col-12 .col-sm-8</div></div>
<div class="col-12 col-sm-8"><div class="p-1 mdl-highlight">.col-12 .col-sm-8</div></div>
</div>
</div>
<pre><div class="row">
<div class="col-12 col-sm-8">.col-12 .col-sm-8</div>
<div class="col-12 col-sm-8">.col-12 .col-sm-8</div>
<!-- Force next columns to break to new line at md breakpoint and up -->
<div class="w-100 d-none d-md-block"></div>
<div class="col-12 col-sm-8">.col-12 .col-sm-8</div>
<div class="col-12 col-sm-8">.col-12 .col-sm-8</div>
</div></pre>
</div>
<p><strong>Reordering</strong></p>
<p><strong>Reordering Order classes</strong></p>
<p>Use <code>.order-</code> classes for controlling the <strong>visual order</strong> of your content. These classes are responsive, so you can set the <code>order</code> by breakpoint (e.g., <code>.order-1.order-md-2</code>). Includes support for <code>1</code> through <code>24</code> across all five grid tiers.</p>
<div class="mdl-example">
<div class="mdl-example-inner">
<div class="container">
<div class="row">
<div class="col">
<div class="p-1 mdl-highlight">First, but unordered</div>
</div>
<div class="col order-12">
<div class="p-1 mdl-highlight">Second, but last</div>
</div>
<div class="col order-1">
<div class="p-1 mdl-highlight">Third, but first</div>
</div>
</div>
</div>
</div>
<pre><div class="container">
<div class="row">
<div class="col">
First, but unordered
</div>
<div class="col order-12">
Second, but last
</div>
<div class="col order-1">
Third, but first
</div>
</div>
</div></pre>
</div>
<p>There are also responsive <code>.order-first</code> and <code>.order-last</code> classes that change the <code>order</code> of an element by applying <code>order: -1</code> and <code>order: 13 (order: $columns + 1)</code>, respectively. These classes can also be intermixed with the numbered <code>.order-*</code> classes as needed.</p>
<p><strong>Offsetting columns</strong></p>
<p>You can offset grid columns in two ways: our responsive <code>.offset-</code> grid classes and our margin utilities. Grid classes are sized to match columns while margins are more useful for quick layouts where the width of the offset is variable.</p>
<p><strong>Offset classes</strong></p>
<p>Move columns to the right using <code>.offset-md-*</code> classes. These classes increase the left margin of a column by <code>*</code> columns. For example, <code>.offset-md-8</code> moves <code>.col-md-8</code> over four columns.</p>
<div class="mdl-example">
<div class="mdl-example-inner">
<div class="row">
<div class="col-md-8"><div class="p-1 mdl-highlight">.col-md-8</div></div>
<div class="col-md-8 offset-md-8"><div class="p-1 mdl-highlight">.col-md-16 .offset-md-16</div></div>
</div>
<div class="row">
<div class="col-md-6 offset-md-6"><div class="p-1 mdl-highlight">.col-md-6 .offset-md-6</div></div>
<div class="col-md-6 offset-md-6"><div class="p-1 mdl-highlight">.col-md-6 .offset-md-6</div></div>
</div>
<div class="row">
<div class="col-md-12 offset-md-6"><div class="p-1 mdl-highlight">.col-md-12 .offset-md-6</div></div>
</div>
</div>
<pre><div class="row">
<div class="col-md-8">.col-md-8</div>
<div class="col-md-8 offset-md-8">.col-md-8 .offset-md-8</div>
</div>
<div class="row">
<div class="col-md-6 offset-md-6">.col-md-6 .offset-md-6</div>
<div class="col-md-6 offset-md-6">.col-md-6 .offset-md-6</div>
</div>
<div class="row">
<div class="col-md-12 offset-md-6">.col-md-12 .offset-md-6</div>
</div></pre>
</div>
<p>In addition to column clearing at responsive breakpoints, you may need to reset offsets. See this in action in the grid example.</p>
<div class="mdl-example">
<div class="mdl-example-inner">
<div class="row">
<div class="col-sm-10 col-md-12"><div class="p-1 mdl-highlight">.col-sm-10 .col-md-12</div></div>
<div class="col-sm-10 offset-sm-4 col-md-12 offset-md-0"><div class="p-1 mdl-highlight">.col-sm-10 .offset-sm-4 .col-md-12 .offset-md-0</div></div>
</div>
<div class="row">
<div class="col-sm-12 col-md-10 col-lg-12"><div class="p-1 mdl-highlight">.col-sm-12 .col-md-10 .col-lg-12</div></div>
<div class="col-sm-12 col-md-10 offset-md-4 col-lg-12 offset-lg-0"><div class="p-1 mdl-highlight">.col-sm-12 .col-md-10 .offset-md-4 .col-lg-12 .offset-lg-0</div></div>
</div>
</div>
<pre><div class="row">
<div class="col-sm-10 col-md-12">.col-sm-10 .col-md-12</div>
<div class="col-sm-10 offset-sm-4 col-md-12 offset-md-0">.col-sm-10 .offset-sm-4 .col-md-12 .offset-md-0</div>
</div>
<div class="row">
<div class="col-sm-12 col-md-10 col-lg-12">.col-sm-12 .col-md-10 .col-lg-12</div>
<div class="col-sm-12 col-md-10 offset-md-4 col-lg-12 offset-lg-0">.col-sm-12 .col-md-10 .offset-md-4 .col-lg-12 .offset-lg-0</div>
</div></pre>
</div>
<p><strong>Margin utilities</strong></p>
<p>With the move to flexbox in v4, you can use margin utilities like <code>.mr-auto</code> to force sibling columns away from one another.</p>
<div class="mdl-example">
<div class="mdl-example-inner">
<div class="row">
<div class="col-md-8"><div class="p-1 mdl-highlight">.col-md-8</div></div>
<div class="col-md-8 ml-auto"><div class="p-1 mdl-highlight">.col-md-8 .ml-auto</div></div>
</div>
<div class="row">
<div class="col-md-6 ml-md-auto"><div class="p-1 mdl-highlight">.col-md-6 .ml-md-auto</div></div>
<div class="col-md-6 ml-md-auto"><div class="p-1 mdl-highlight">.col-md-6 .ml-md-auto</div></div>
</div>
<div class="row">
<div class="col-auto mr-auto"><div class="p-1 mdl-highlight">.col-auto .mr-auto</div></div>
<div class="col-auto"><div class="p-1 mdl-highlight">.col-auto</div></div>
</div>
</div>
<pre><div class="row">
<div class="col-md-8">.col-md-8</div>
<div class="col-md-8 ml-auto">.col-md-8 .ml-auto</div>
</div>
<div class="row">
<div class="col-md-6 ml-md-auto">.col-md-6 .ml-md-auto</div>
<div class="col-md-6 ml-md-auto">.col-md-6 .ml-md-auto</div>
</div>
<div class="row">
<div class="col-auto mr-auto">.col-auto .mr-auto</div>
<div class="col-auto">.col-auto</div>
</div></pre>
</div>
<p><strong>Nesting</strong></p>
<p>To nest your content with the default grid, add a new <code>.row</code> and set of <code>.col-sm-*</code> columns within an existing <code>.col-sm-*</code> column. Nested rows should include a set of columns that add up to 12 or fewer (it is not required that you use all 12 available columns).</p>
<div class="mdl-example">
<div class="mdl-example-inner">
<div class="row">
<div class="col-sm-18">
<div class="p-1 mdl-highlight">
Level 1: .col-sm-18
<div class="row">
<div class="col-16 col-sm-12">
<div class="p-1 mdl-highlight">Level 2: .col-16 .col-sm-12</div>
</div>
<div class="col-8 col-sm-12">
<div class="p-1 mdl-highlight">Level 2: .col-8 .col-sm-12</div>
</div>
</div>
</div>
</div>
</div>
</div>
<pre><div class="row">
<div class="col-sm-18">
Level 1: .col-sm-18
<div class="row">
<div class="col-16 col-sm-12">
Level 2: .col-16 .col-sm-12
</div>
<div class="col-8 col-sm-12">
Level 2: .col-8 .col-sm-12
</div>
</div>
</div>
</div></pre>
</div>
<p><strong>Sass mixins</strong></p>
<p>When using Bootstrap’s source Sass files, you have the option of using Sass variables and mixins to create custom, semantic, and responsive page layouts. Our predefined grid classes use these same variables and mixins to provide a whole suite of ready-to-use classes for fast responsive layouts.</p>
<p><strong>Variables</strong></p>
<p>Variables and maps determine the number of columns, the gutter width, and the media query point at which to begin floating columns. We use these to generate the predefined grid classes documented above, as well as for the custom mixins listed below.</p>
<pre class="mdl-code">
$grid-columns: 12;
$grid-gutter-width: 30px;
$grid-breakpoints: (
// Extra small screen / phone
xs: 0,
// Small screen / phone
sm: 576px,
// Medium screen / tablet
md: 768px,
// Large screen / desktop
lg: 992px,
// Extra large screen / wide desktop
xl: 1200px
);
$container-max-widths: (
sm: 540px,
md: 720px,
lg: 960px,
xl: 1140px
);
</pre>
<p><strong>Mixins</strong></p>
<p>Mixins are used in conjunction with the grid variables to generate semantic CSS for individual grid columns.</p>
<pre class="mdl-code">
// Creates a wrapper for a series of columns
@include make-row();
// Make the element grid-ready (applying everything but the width)
@include make-col-ready();
@include make-col($size, $columns: $grid-columns);
// Get fancy by offsetting, or changing the sort order
@include make-col-offset($size, $columns: $grid-columns);
</pre>
<p><strong>Example usage</strong></p>
<p>You can modify the variables to your own custom values, or just use the mixins with their default values. Here’s an example of using the default settings to create a two-column layout with a gap between.</p>
<pre class="mdl-code">
.example-container {
width: 800px;
@include make-container();
}
.example-row {
@include make-row();
}
.example-content-main {
@include make-col-ready();
@include media-breakpoint-up(sm) {
@include make-col(6);
}
@include media-breakpoint-up(lg) {
@include make-col(8);
}
}
.example-content-secondary {
@include make-col-ready();
@include media-breakpoint-up(sm) {
@include make-col(6);
}
@include media-breakpoint-up(lg) {
@include make-col(4);
}
}
</pre>
<p></p>
<div class="mdl-example">
<div class="mdl-example-inner">
<div class="example-container">
<div class="example-row" style="display: flex;">
<div class="example-content-main" style="flex: 0 0 66.666667%;max-width: 66.666667%;">Main content</div>
<div class="example-content-secondary" style="flex: 0 0 33.333333%; max-width: 33.333333%;">Secondary content</div>
</div>
</div>
</div>
<pre>
<div class="example-container">
<div class="example-row">
<div class="example-content-main">Main content</div>
<div class="example-content-secondary">Secondary content</div>
</div>
</div></pre>
</div>
<p><strong>Customizing the grid</strong></p>
<p>Using our built-in grid Sass variables and maps, it’s possible to completely customize the predefined grid classes. Change the number of tiers, the media query dimensions, and the container widths—then recompile.</p>
<p><strong>Columns and gutters</strong></p>
<p>The number of grid columns can be modified via Sass variables. <code>$grid-columns</code> is used to generate the widths (in percent) of each individual column while <code>$grid-gutter-width</code> allows breakpoint-specific widths that are divided evenly across <code>padding-left</code> and <code>padding-right</code> for the column gutters.</p>
<pre>
$grid-columns: 12 !default;
$grid-gutter-width: 30px !default;
</pre>
<p><strong>Grid tiers</strong></p>
<p>Moving beyond the columns themselves, you may also customize the number of grid tiers. If you wanted just four grid tiers, you’d update the <code>$grid-breakpoints</code> and <code>$container-max-widths</code> to something like this:</p>
<pre class="mdl-code">
$grid-breakpoints: (
xs: 0,
sm: 480px,
md: 768px,
lg: 1024px
);
$container-max-widths: (
sm: 420px,
md: 720px,
lg: 960px
);
</pre>
<p>When making any changes to the Sass variables or maps, you’ll need to save your changes and recompile. Doing so will output a brand new set of predefined grid classes for column widths, offsets, and ordering. Responsive visibility utilities will also be updated to use the custom breakpoints. Make sure to set grid values in <code>px</code> (not <code> rem</code>, <code>em</code>, or <code>%</code>).</p>
/*!
* Bootstrap Grid v4.0.0-beta.3 (https://getbootstrap.com)
* Copyright 2011-2017 The Bootstrap Authors
* Copyright 2011-2017 Twitter, Inc.
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
*/
@import "vars";
@import "~bootstrap/scss/mixins/grid-framework";
@import "~bootstrap/scss/mixins/grid";
@import "~bootstrap/scss/grid";
@import "~bootstrap/scss/utilities/flex";
@at-root {
// sass-lint:disable no-vendor-prefixes
@-ms-viewport {
width: device-width;
}
// sass-lint:enable no-vendor-prefixes
}
html,
body {
height: 100%;
&.no-scroll {
overflow: hidden;
}
}
html {
-ms-overflow-style: scrollbar; // sass-lint:disable-line no-vendor-prefixes
box-sizing: border-box;
font-size: 62.5%;
overflow-x: hidden;
scroll-behavior: smooth;
&.wf-loading {
* {
color: transparent !important; // sass-lint:disable-line no-important
}
}
&:before {
$length: length($grid-breakpoints);
$keys: map-keys($grid-breakpoints);
@if $length > 1 {
$breakpoints-content: '{"';
@each $name, $value in $grid-breakpoints {
$next: breakpoint-next($name, $grid-breakpoints);
$value: breakpoint-min($name);
@if $value {
$breakpoints-content: str-insert($breakpoints-content, $name + '" : "(min-width: ' + $value + ')', -1);
}
@if $next {
$sep: if($value, ' and ', $name + '" : "');
$breakpoints-content: str-insert($breakpoints-content, $sep + '(max-width: ' + (breakpoint-min($next) - .001em) + ')", "', -1);
} @else {
$breakpoints-content: str-insert($breakpoints-content, '"', -1);
}
}
@if variable-exists(menu-breakpoint) {
$breakpoints-content: str-insert($breakpoints-content, ', "menu" : "(min-width: ' + breakpoint-min($menu-breakpoint) + ')"', -1);
}
$breakpoints-content: str-insert($breakpoints-content, '}', -1);
content: $breakpoints-content;
display: none;
}
}
}
body {
display: flex; // Setup to sticky footer
flex-direction: column;
height: 100vh;
&.js-focus-visible {
:focus {
&:not(.focus-visible) {
outline: none;
}
}
}
}
*,
*:before,
*:after {
box-sizing: inherit;
}
img {
height: auto;
max-width: 100%;
}
.container {
&-1240 {
max-width: map-get($container-max-widths, 'xl');
}
&-960 {
max-width: map-get($container-max-widths, 'lg');
}
&-770 {
max-width: map-get($container-max-widths, 'md');
}
}
.row {
margin-bottom: -($grid-gutter-width / 2);
margin-top: -($grid-gutter-width / 2);
> .col,
> [class*="col-"] {
margin-bottom: ($grid-gutter-width / 2);
margin-top: ($grid-gutter-width / 2);
}
&.no-gutters {
margin-bottom: 0;
margin-top: 0;
> .col,
> [class*="col-"] {
margin-bottom: 0;
margin-top: 0;
}
}
&.line-gutters {
margin: -1px 0 0 -1px;
> .col,
> [class*="col-"] {
margin-bottom: 0;
margin-top: 1px;
padding-left: 1px;
padding-right: 0;
}
}
}