Skip to main content

Layout

Grid

The twelve-column flexbox grid — containers, rows and columns, with six responsive tiers.

Example

The grid is a series of containers, rows and columns built on flexbox. It is fully responsive and mobile first. The theme keeps Bootstrap's twelve columns and six tiers; what changes is the gutter scale, which follows the 4px spacing tokens.

Column
Column
Column
HTML
<div class="container text-center">
  <div class="row">
    <div class="col"><div class="border bg-body-tertiary p-3">Column</div></div>
    <div class="col"><div class="border bg-body-tertiary p-3">Column</div></div>
    <div class="col"><div class="border bg-body-tertiary p-3">Column</div></div>
  </div>
</div>

Three equal-width columns on every viewport, with no breakpoint classes at all.

How it works

  • The grid supports six responsive breakpoints. Breakpoints are based on min-width media queries, so a class applies at that breakpoint and all above it. See Breakpoints.
  • Containers center and pad your content. Use .container for a responsive width, .container-fluid for 100% width, or .container-{breakpoint} for a mix. See Containers.
  • Rows are wrappers for columns. Each column has horizontal padding (the gutter); the row cancels it with a negative margin so content lines up with the container edge.
  • Columns are flexible. Twelve template columns per row. .col-4 takes four of them. Widths are percentages, so columns stay the same size relative to the parent.
  • Gutters are responsive and customisable. .g-{0–8}, .gx-* and .gy-* use the theme's nine-step scale. .g-0 removes them.
  • Sass variables, maps and mixins power the grid. Or skip the classes and use the mixins directly.
Need real two-dimensional layout? The theme also compiles Bootstrap's opt-in CSS grid (.grid, .g-col-*). Both systems coexist.

Grid options

How the grid behaves across breakpoints:

xs
<576px
sm
≥576px
md
≥768px
lg
≥992px
xl
≥1200px
xxl
≥1400px
Container max-widthNone (auto)540px720px960px1140px1320px
Class prefix.col-.col-sm-.col-md-.col-lg-.col-xl-.col-xxl-
# of columns12
Gutter width1.5rem (.75rem on left and right) — the same as .g-5 on this scale
Custom guttersYes, nine steps from .g-0 to .g-8
NestableYes
Column orderingYes

Auto-layout columns

Breakpoint-specific column classes for easy sizing without an explicit number, like .col-sm-6.

Equal-width

Two grids that expand and fill the available width. Two columns in the first row, three in the second, and they remain equal at every breakpoint.

1 of 2
2 of 2
1 of 3
2 of 3
3 of 3
HTML
<div class="container text-center">
  <div class="row">
    <div class="col"><div class="border bg-body-tertiary p-3">1 of 2</div></div>
    <div class="col"><div class="border bg-body-tertiary p-3">2 of 2</div></div>
  </div>
  <div class="row mt-3">
    <div class="col"><div class="border bg-body-tertiary p-3">1 of 3</div></div>
    <div class="col"><div class="border bg-body-tertiary p-3">2 of 3</div></div>
    <div class="col"><div class="border bg-body-tertiary p-3">3 of 3</div></div>
  </div>
</div>

Setting one column width

Set the width of one column and the siblings resize around it. Use predefined classes as shown; the other columns can be any width, as long as the total fits.

1 of 3
2 of 3 (wider)
3 of 3
1 of 3
2 of 3 (wider)
3 of 3
HTML
<div class="container text-center">
  <div class="row">
    <div class="col"><div class="border bg-body-tertiary p-3">1 of 3</div></div>
    <div class="col-6"><div class="border bg-body-tertiary p-3">2 of 3 (wider)</div></div>
    <div class="col"><div class="border bg-body-tertiary p-3">3 of 3</div></div>
  </div>
  <div class="row mt-3">
    <div class="col"><div class="border bg-body-tertiary p-3">1 of 3</div></div>
    <div class="col-5"><div class="border bg-body-tertiary p-3">2 of 3 (wider)</div></div>
    <div class="col"><div class="border bg-body-tertiary p-3">3 of 3</div></div>
  </div>
</div>

Variable width content

Use .col-{breakpoint}-auto to size a column by the natural width of its content. Here the middle column shrinks to its label and the outer two share the rest.

1 of 3
Variable width content
3 of 3
1 of 3
Variable width content
3 of 3
HTML
<div class="container text-center">
  <div class="row justify-content-md-center">
    <div class="col col-lg-2"><div class="border bg-body-tertiary p-3">1 of 3</div></div>
    <div class="col-md-auto"><div class="border bg-body-tertiary p-3">Variable width content</div></div>
    <div class="col col-lg-2"><div class="border bg-body-tertiary p-3">3 of 3</div></div>
  </div>
  <div class="row mt-3">
    <div class="col"><div class="border bg-body-tertiary p-3">1 of 3</div></div>
    <div class="col-md-auto"><div class="border bg-body-tertiary p-3">Variable width content</div></div>
    <div class="col col-lg-2"><div class="border bg-body-tertiary p-3">3 of 3</div></div>
  </div>
</div>

Responsive classes

Six tiers of predefined classes for building complex layouts.

All breakpoints

For grids that are the same from the smallest devices to the largest, use .col and .col-* with no infix. Specify a number only when you need a particular size.

col
col
col
col
col-8
col-4
HTML
<div class="container text-center">
  <div class="row">
    <div class="col"><div class="border bg-body-tertiary p-3">col</div></div>
    <div class="col"><div class="border bg-body-tertiary p-3">col</div></div>
    <div class="col"><div class="border bg-body-tertiary p-3">col</div></div>
    <div class="col"><div class="border bg-body-tertiary p-3">col</div></div>
  </div>
  <div class="row mt-3">
    <div class="col-8"><div class="border bg-body-tertiary p-3">col-8</div></div>
    <div class="col-4"><div class="border bg-body-tertiary p-3">col-4</div></div>
  </div>
</div>

Stacked to horizontal

With a single set of .col-sm-* classes the columns start stacked and become horizontal at 576px. Resize the window to see it happen.

col-sm-8
col-sm-4
col-sm
col-sm
col-sm
HTML
<div class="container text-center">
  <div class="row">
    <div class="col-sm-8"><div class="border bg-body-tertiary p-3">col-sm-8</div></div>
    <div class="col-sm-4"><div class="border bg-body-tertiary p-3">col-sm-4</div></div>
  </div>
  <div class="row mt-3">
    <div class="col-sm"><div class="border bg-body-tertiary p-3">col-sm</div></div>
    <div class="col-sm"><div class="border bg-body-tertiary p-3">col-sm</div></div>
    <div class="col-sm"><div class="border bg-body-tertiary p-3">col-sm</div></div>
  </div>
</div>

Mix and match

Combine classes from several tiers. Each row below stacks on the smallest screens and takes a different shape as the viewport grows.

.col-md-8
.col-6 .col-md-4
.col-6 .col-md-4
.col-6 .col-md-4
.col-6 .col-md-4
.col-6
.col-6
HTML
<div class="container text-center">
  <!-- Stack the columns on mobile by making one full-width and the other half-width -->
  <div class="row">
    <div class="col-md-8"><div class="border bg-body-tertiary p-3">.col-md-8</div></div>
    <div class="col-6 col-md-4"><div class="border bg-body-tertiary p-3">.col-6 .col-md-4</div></div>
  </div>

  <!-- Columns start at 50% wide on mobile and bump up to 33.3% wide on desktop -->
  <div class="row mt-3">
    <div class="col-6 col-md-4"><div class="border bg-body-tertiary p-3">.col-6 .col-md-4</div></div>
    <div class="col-6 col-md-4"><div class="border bg-body-tertiary p-3">.col-6 .col-md-4</div></div>
    <div class="col-6 col-md-4"><div class="border bg-body-tertiary p-3">.col-6 .col-md-4</div></div>
  </div>

  <!-- Columns are always 50% wide, on mobile and desktop -->
  <div class="row mt-3">
    <div class="col-6"><div class="border bg-body-tertiary p-3">.col-6</div></div>
    <div class="col-6"><div class="border bg-body-tertiary p-3">.col-6</div></div>
  </div>
</div>

Row columns

Set the number of columns per row from the row with .row-cols-*. The value goes from 1 to 6, plus .row-cols-auto for natural widths. Children can still override with .col-* classes.

Column
Column
Column
Column
HTML
<div class="container text-center">
  <div class="row row-cols-2">
    <div class="col"><div class="border bg-body-tertiary p-3">Column</div></div>
    <div class="col"><div class="border bg-body-tertiary p-3">Column</div></div>
    <div class="col"><div class="border bg-body-tertiary p-3">Column</div></div>
    <div class="col"><div class="border bg-body-tertiary p-3">Column</div></div>
  </div>
</div>
Column
Column
Column
Column
HTML
<div class="container text-center">
  <div class="row row-cols-3">
    <div class="col"><div class="border bg-body-tertiary p-3">Column</div></div>
    <div class="col"><div class="border bg-body-tertiary p-3">Column</div></div>
    <div class="col"><div class="border bg-body-tertiary p-3">Column</div></div>
    <div class="col"><div class="border bg-body-tertiary p-3">Column</div></div>
  </div>
</div>
Column
Column
Column
Column
HTML
<div class="container text-center">
  <div class="row row-cols-auto">
    <div class="col"><div class="border bg-body-tertiary p-3">Column</div></div>
    <div class="col"><div class="border bg-body-tertiary p-3">Column</div></div>
    <div class="col"><div class="border bg-body-tertiary p-3">Column</div></div>
    <div class="col"><div class="border bg-body-tertiary p-3">Column</div></div>
  </div>
</div>
Column
Column
Column (.col-6)
Column
HTML
<div class="container text-center">
  <div class="row row-cols-4">
    <div class="col"><div class="border bg-body-tertiary p-3">Column</div></div>
    <div class="col"><div class="border bg-body-tertiary p-3">Column</div></div>
    <div class="col-6"><div class="border bg-body-tertiary p-3">Column (.col-6)</div></div>
    <div class="col"><div class="border bg-body-tertiary p-3">Column</div></div>
  </div>
</div>

Row columns take responsive infixes too. One per row on phones, three from md:

Column
Column
Column
Column
Column
Column
HTML
<div class="container text-center">
  <div class="row row-cols-1 row-cols-sm-2 row-cols-md-3">
    <div class="col"><div class="border bg-body-tertiary p-3">Column</div></div>
    <div class="col"><div class="border bg-body-tertiary p-3">Column</div></div>
    <div class="col"><div class="border bg-body-tertiary p-3">Column</div></div>
    <div class="col"><div class="border bg-body-tertiary p-3">Column</div></div>
    <div class="col"><div class="border bg-body-tertiary p-3">Column</div></div>
    <div class="col"><div class="border bg-body-tertiary p-3">Column</div></div>
  </div>
</div>

The row-cols() mixin does the same from Sass:

.element {
  // Three per row at the baseline
  @include row-cols(3);
}

.element-two {
  @include media-breakpoint-up(md) {
    // Four per row from md
    @include row-cols(4);
  }
}

Nesting

To nest, add a .row and .col-* columns inside an existing column. Nested rows should include no more than twelve columns, though you need not fill all twelve.

Level 1: .col-sm-3
Level 2: .col-8 .col-sm-6
Level 2: .col-4 .col-sm-6
HTML
<div class="container text-center">
  <div class="row">
    <div class="col-sm-3">
      <div class="border bg-body-tertiary p-3">Level 1: .col-sm-3</div>
    </div>
    <div class="col-sm-9">
      <div class="row">
        <div class="col-8 col-sm-6"><div class="border bg-body-tertiary p-3">Level 2: .col-8 .col-sm-6</div></div>
        <div class="col-4 col-sm-6"><div class="border bg-body-tertiary p-3">Level 2: .col-4 .col-sm-6</div></div>
      </div>
    </div>
  </div>
</div>

Sass

Bootstrap's grid variables and mixins build the classes above and can build semantic markup of your own. The theme does not change any of them, so the defaults below are what you get.

Variables

$grid-columns:      12;
$grid-gutter-width: 1.5rem;
$grid-row-columns:  6;

$grid-breakpoints: (
  xs: 0,
  sm: 576px,
  md: 768px,
  lg: 992px,
  xl: 1200px,
  xxl: 1400px
);

$container-max-widths: (
  sm: 540px,
  md: 720px,
  lg: 960px,
  xl: 1140px,
  xxl: 1320px
);

Note that .g-* gutter classes do not come from $grid-gutter-width; they are built from the theme's $spacers map. See Gutters.

Mixins

Mixins are used in conjunction with the grid variables to generate semantic CSS for individual grid columns.

// Create a container
@include make-container();

// Create a row
@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 is a card-of-the-night layout with a main column and a sidebar from md up.

.card-of-the-night {
  @include make-row();
}

.card-main,
.card-sidebar {
  @include make-col-ready();

  @include media-breakpoint-up(md) {
    @include make-col(8);
  }
}

.card-sidebar {
  @include media-breakpoint-up(md) {
    @include make-col(4);
  }
}
<div class="card-of-the-night">
  <div class="card-main">Main event, Royal Rumble 1992</div>
  <div class="card-sidebar">Undercard</div>
</div>

Customizing the grid

Using the built-in grid Sass variables and maps, it is possible to completely customise 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 sets the default column padding.

$grid-columns: 16;
$grid-gutter-width: 2rem;

@import "@ropebreak/bootstrap/scss/rb-bootstrap";

Grid tiers

Moving beyond the columns themselves, you may also customise the number of grid tiers. If you only wanted four, update $grid-breakpoints and $container-max-widths together.

$grid-breakpoints: (
  xs: 0,
  sm: 480px,
  md: 768px,
  lg: 1024px
);

$container-max-widths: (
  sm: 420px,
  md: 720px,
  lg: 960px
);

@import "@ropebreak/bootstrap/scss/rb-bootstrap";

When making any changes to the Sass variables or maps, save your changes and recompile. Doing so will output a new set of predefined grid classes for column widths, offsets and ordering. Responsive visibility utilities and the CSS grid classes are updated to use the custom breakpoints too.