Skip to main content

Layout

Columns

Aligning, ordering, offsetting and wrapping columns inside the flexbox grid.

How they work

  • Columns build on the grid's flexbox architecture. Flexbox means you have options for changing individual columns and modifying groups of columns at the row level. You choose how columns grow, shrink or otherwise change.
  • When building grid layouts, all content goes in columns. The hierarchy goes container → row → column → your content. On rare occasions you may combine content and column, but be aware there can be unintended consequences.
  • The theme includes predefined classes for creating fast, responsive layouts. With six breakpoints and a dozen columns at each tier, there are dozens of classes already built for you. Or use the Sass mixins for your own.
Many of the classes on this page are flex utilities applied to a .row. Anything that works on a flex container works on a row.

Alignment

Use flexbox alignment utilities to vertically and horizontally align columns.

Vertical alignment

Change the vertical alignment with any of the responsive align-items-* classes on the row. The rows below are given a fixed height so you can see the difference.

One of three columns
One of three columns
One of three columns
One of three columns
One of three columns
One of three columns
One of three columns
One of three columns
One of three columns
HTML
<div class="container text-center">
  <div class="row align-items-start bg-body-secondary mb-3" style="min-height: 7rem">
    <div class="col"><div class="border bg-body-tertiary p-3">One of three columns</div></div>
    <div class="col"><div class="border bg-body-tertiary p-3">One of three columns</div></div>
    <div class="col"><div class="border bg-body-tertiary p-3">One of three columns</div></div>
  </div>
  <div class="row align-items-center bg-body-secondary mb-3" style="min-height: 7rem">
    <div class="col"><div class="border bg-body-tertiary p-3">One of three columns</div></div>
    <div class="col"><div class="border bg-body-tertiary p-3">One of three columns</div></div>
    <div class="col"><div class="border bg-body-tertiary p-3">One of three columns</div></div>
  </div>
  <div class="row align-items-end bg-body-secondary" style="min-height: 7rem">
    <div class="col"><div class="border bg-body-tertiary p-3">One of three columns</div></div>
    <div class="col"><div class="border bg-body-tertiary p-3">One of three columns</div></div>
    <div class="col"><div class="border bg-body-tertiary p-3">One of three columns</div></div>
  </div>
</div>

Or align a single column with align-self-*:

One of three columns
One of three columns
One of three columns
HTML
<div class="container text-center">
  <div class="row bg-body-secondary" style="min-height: 7rem">
    <div class="col align-self-start"><div class="border bg-body-tertiary p-3">One of three columns</div></div>
    <div class="col align-self-center"><div class="border bg-body-tertiary p-3">One of three columns</div></div>
    <div class="col align-self-end"><div class="border bg-body-tertiary p-3">One of three columns</div></div>
  </div>
</div>

Horizontal alignment

Change the horizontal alignment with any of the responsive justify-content-* classes.

One of two columns
One of two columns
One of two columns
One of two columns
One of two columns
One of two columns
One of two columns
One of two columns
One of two columns
One of two columns
One of two columns
One of two columns
HTML
<div class="container text-center">
  <div class="row justify-content-start mb-3">
    <div class="col-4"><div class="border bg-body-tertiary p-3">One of two columns</div></div>
    <div class="col-4"><div class="border bg-body-tertiary p-3">One of two columns</div></div>
  </div>
  <div class="row justify-content-center mb-3">
    <div class="col-4"><div class="border bg-body-tertiary p-3">One of two columns</div></div>
    <div class="col-4"><div class="border bg-body-tertiary p-3">One of two columns</div></div>
  </div>
  <div class="row justify-content-end mb-3">
    <div class="col-4"><div class="border bg-body-tertiary p-3">One of two columns</div></div>
    <div class="col-4"><div class="border bg-body-tertiary p-3">One of two columns</div></div>
  </div>
  <div class="row justify-content-around mb-3">
    <div class="col-4"><div class="border bg-body-tertiary p-3">One of two columns</div></div>
    <div class="col-4"><div class="border bg-body-tertiary p-3">One of two columns</div></div>
  </div>
  <div class="row justify-content-between mb-3">
    <div class="col-4"><div class="border bg-body-tertiary p-3">One of two columns</div></div>
    <div class="col-4"><div class="border bg-body-tertiary p-3">One of two columns</div></div>
  </div>
  <div class="row justify-content-evenly">
    <div class="col-4"><div class="border bg-body-tertiary p-3">One of two columns</div></div>
    <div class="col-4"><div class="border bg-body-tertiary p-3">One of two columns</div></div>
  </div>
</div>

Column wrapping

If more than twelve columns are placed within a single row, each group of extra columns will, as one unit, wrap onto a new line.

.col-9
.col-4
Since 9 + 4 = 13 > 12, this 4-column-wide div gets wrapped onto a new line as one contiguous unit.
.col-6
Subsequent columns continue along the new line.
HTML
<div class="container text-center">
  <div class="row">
    <div class="col-9"><div class="border bg-body-tertiary p-3">.col-9</div></div>
    <div class="col-4"><div class="border bg-body-tertiary p-3">.col-4<br>Since 9 + 4 = 13 &gt; 12, this 4-column-wide div gets wrapped onto a new line as one contiguous unit.</div></div>
    <div class="col-6"><div class="border bg-body-tertiary p-3">.col-6<br>Subsequent columns continue along the new line.</div></div>
  </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 can account for that.

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

    <!-- Force next columns to break to new line -->
    <div class="w-100"></div>

    <div class="col-6 col-sm-3"><div class="border bg-body-tertiary p-3">.col-6 .col-sm-3</div></div>
    <div class="col-6 col-sm-3"><div class="border bg-body-tertiary p-3">.col-6 .col-sm-3</div></div>
  </div>
</div>

You may also apply this break at specific breakpoints with the responsive display utilities.

.col-6 .col-sm-4
.col-6 .col-sm-4
.col-6 .col-sm-4
.col-6 .col-sm-4
HTML
<div class="container text-center">
  <div class="row">
    <div class="col-6 col-sm-4"><div class="border bg-body-tertiary p-3">.col-6 .col-sm-4</div></div>
    <div class="col-6 col-sm-4"><div class="border bg-body-tertiary p-3">.col-6 .col-sm-4</div></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-6 col-sm-4"><div class="border bg-body-tertiary p-3">.col-6 .col-sm-4</div></div>
    <div class="col-6 col-sm-4"><div class="border bg-body-tertiary p-3">.col-6 .col-sm-4</div></div>
  </div>
</div>

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 5 across all six grid tiers. If you need more .order-* classes, change the $utilities map.

First in DOM, no order applied
Second in DOM, with a larger order
Third in DOM, with an order of 1
HTML
<div class="container text-center">
  <div class="row">
    <div class="col"><div class="border bg-body-tertiary p-3">First in DOM, no order applied</div></div>
    <div class="col order-5"><div class="border bg-body-tertiary p-3">Second in DOM, with a larger order</div></div>
    <div class="col order-1"><div class="border bg-body-tertiary p-3">Third in DOM, with an order of 1</div></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: 6, respectively. These classes can also be intermixed with the numbered .order-* classes as needed.

First in DOM, ordered last
Second in DOM, unordered
Third in DOM, ordered first
HTML
<div class="container text-center">
  <div class="row">
    <div class="col order-last"><div class="border bg-body-tertiary p-3">First in DOM, ordered last</div></div>
    <div class="col"><div class="border bg-body-tertiary p-3">Second in DOM, unordered</div></div>
    <div class="col order-first"><div class="border bg-body-tertiary p-3">Third in DOM, ordered first</div></div>
  </div>
</div>
Visual order is not reading order. Screen readers and the Tab key follow the DOM. Put the content that must come first — the main event, not the dark match — first in the markup, and use .order-* only for presentation.

Offsetting columns

You can offset grid columns in two ways: the responsive .offset- grid classes and the 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-4 moves .col-md-4 over four columns.

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

In addition to column clearing at responsive breakpoints, you may need to reset offsets. See this in action in the example below.

.col-sm-5 .col-md-6
.col-sm-5 .offset-sm-2 .col-md-6 .offset-md-0
.col-sm-6 .col-md-5 .col-lg-6
.col-sm-6 .col-md-5 .offset-md-2 .col-lg-6 .offset-lg-0
HTML
<div class="container text-center">
  <div class="row">
    <div class="col-sm-5 col-md-6"><div class="border bg-body-tertiary p-3">.col-sm-5 .col-md-6</div></div>
    <div class="col-sm-5 offset-sm-2 col-md-6 offset-md-0"><div class="border bg-body-tertiary p-3">.col-sm-5 .offset-sm-2 .col-md-6 .offset-md-0</div></div>
  </div>
  <div class="row mt-3">
    <div class="col-sm-6 col-md-5 col-lg-6"><div class="border bg-body-tertiary p-3">.col-sm-6 .col-md-5 .col-lg-6</div></div>
    <div class="col-sm-6 col-md-5 offset-md-2 col-lg-6 offset-lg-0"><div class="border bg-body-tertiary p-3">.col-sm-6 .col-md-5 .offset-md-2 .col-lg-6 .offset-lg-0</div></div>
  </div>
</div>

Margin utilities

With flexbox you can use margin utilities like .me-auto to force sibling columns away from one another. Remember the theme's spacing scale runs 0–8: a fixed push of .ms-5 is 1.5rem here, and .ms-7 is the 3rem that stock Bootstrap called .ms-5.

.col-md-4
.col-md-4 .ms-auto
.col-md-3 .ms-md-auto
.col-md-3 .ms-md-auto
.col-auto .me-auto
.col-auto
HTML
<div class="container text-center">
  <div class="row">
    <div class="col-md-4"><div class="border bg-body-tertiary p-3">.col-md-4</div></div>
    <div class="col-md-4 ms-auto"><div class="border bg-body-tertiary p-3">.col-md-4 .ms-auto</div></div>
  </div>
  <div class="row mt-3">
    <div class="col-md-3 ms-md-auto"><div class="border bg-body-tertiary p-3">.col-md-3 .ms-md-auto</div></div>
    <div class="col-md-3 ms-md-auto"><div class="border bg-body-tertiary p-3">.col-md-3 .ms-md-auto</div></div>
  </div>
  <div class="row mt-3">
    <div class="col-auto me-auto"><div class="border bg-body-tertiary p-3">.col-auto .me-auto</div></div>
    <div class="col-auto"><div class="border bg-body-tertiary p-3">.col-auto</div></div>
  </div>
</div>

Standalone column classes

The .col-* classes can also be used outside a .row to give an element a specific width. Whenever column classes are used as non-direct children of a row, the paddings are omitted.

.col-3: width of 25%
.col-sm-9: width of 75% above sm breakpoint
HTML
<div class="col-3 border bg-body-tertiary p-3 mb-3">.col-3: width of 25%</div>
<div class="col-sm-9 border bg-body-tertiary p-3">.col-sm-9: width of 75% above sm breakpoint</div>

The classes can be used together with utilities to create responsive floated images. Make sure to wrap the content in a clearfix wrapper to clear the float if the text is shorter.

Responsive floated image

The Intercontinental title picture heading into the summer was crowded. Four contenders, one belt, and a champion who had not lost clean in fourteen months. The booking committee wanted a tournament. Television wanted a ladder match. The champion wanted a holiday.

What the fans got was a four-week series of number-one contender bouts, each one ending in a double-countout, until the commissioner lost patience and ordered a fatal four-way for the pay-per-view. It drew the best buyrate of the year.

HTML
<div class="clearfix">
  <svg class="col-md-6 float-md-end mb-3 ms-md-3" width="100%" height="140" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Placeholder: Responsive floated image"><rect width="100%" height="100%" fill="var(--bs-secondary-bg)"/><text x="50%" y="50%" fill="var(--bs-secondary-color)" dy=".3em" text-anchor="middle">Responsive floated image</text></svg>
  <p>
    The Intercontinental title picture heading into the summer was crowded. Four contenders, one belt, and
    a champion who had not lost clean in fourteen months. The booking committee wanted a tournament.
    Television wanted a ladder match. The champion wanted a holiday.
  </p>
  <p>
    What the fans got was a four-week series of number-one contender bouts, each one ending in a
    double-countout, until the commissioner lost patience and ordered a fatal four-way for the pay-per-view.
    It drew the best buyrate of the year.
  </p>
</div>