Heads up! Be sure to read the Grid page first before diving into how to modify and customize your grid columns.

How they work

  • Columns build on the grid’s flexbox architecture. Flexbox means we 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 of Bootstrap’s grid goes from container to row to column to your content. On rare occasions, you may combine content and column, but be aware there can be unintended consequences.

  • Bootstrap includes predefined classes for creating fast, responsive layouts. With six breakpoints and a dozen columns at each grid tier, we have dozens of classes already built for you to create your desired layouts. This can be disabled via Sass if you wish.

Alignment

Use flexbox alignment utilities to vertically and horizontally align columns.

Vertical alignment

Columns - 图1

  1. <div class="container">
  2. <div class="row align-items-start">
  3. <div class="col">
  4. One of three columns
  5. </div>
  6. <div class="col">
  7. One of three columns
  8. </div>
  9. <div class="col">
  10. One of three columns
  11. </div>
  12. </div>
  13. <div class="row align-items-center">
  14. <div class="col">
  15. One of three columns
  16. </div>
  17. <div class="col">
  18. One of three columns
  19. </div>
  20. <div class="col">
  21. One of three columns
  22. </div>
  23. </div>
  24. <div class="row align-items-end">
  25. <div class="col">
  26. One of three columns
  27. </div>
  28. <div class="col">
  29. One of three columns
  30. </div>
  31. <div class="col">
  32. One of three columns
  33. </div>
  34. </div>
  35. </div>

Columns - 图2

  1. <div class="container">
  2. <div class="row">
  3. <div class="col align-self-start">
  4. One of three columns
  5. </div>
  6. <div class="col align-self-center">
  7. One of three columns
  8. </div>
  9. <div class="col align-self-end">
  10. One of three columns
  11. </div>
  12. </div>
  13. </div>

Horizontal alignment

Columns - 图3

  1. <div class="container">
  2. <div class="row justify-content-start">
  3. <div class="col-4">
  4. One of two columns
  5. </div>
  6. <div class="col-4">
  7. One of two columns
  8. </div>
  9. </div>
  10. <div class="row justify-content-center">
  11. <div class="col-4">
  12. One of two columns
  13. </div>
  14. <div class="col-4">
  15. One of two columns
  16. </div>
  17. </div>
  18. <div class="row justify-content-end">
  19. <div class="col-4">
  20. One of two columns
  21. </div>
  22. <div class="col-4">
  23. One of two columns
  24. </div>
  25. </div>
  26. <div class="row justify-content-around">
  27. <div class="col-4">
  28. One of two columns
  29. </div>
  30. <div class="col-4">
  31. One of two columns
  32. </div>
  33. </div>
  34. <div class="row justify-content-between">
  35. <div class="col-4">
  36. One of two columns
  37. </div>
  38. <div class="col-4">
  39. One of two columns
  40. </div>
  41. </div>
  42. <div class="row justify-content-evenly">
  43. <div class="col-4">
  44. One of two columns
  45. </div>
  46. <div class="col-4">
  47. One of two columns
  48. </div>
  49. </div>
  50. </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.

Columns - 图4

  1. <div class="container">
  2. <div class="row">
  3. <div class="col-9">.col-9</div>
  4. <div class="col-4">.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>
  5. <div class="col-6">.col-6<br>Subsequent columns continue along the new line.</div>
  6. </div>
  7. </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.

Columns - 图5

  1. <div class="container">
  2. <div class="row">
  3. <div class="col-6 col-sm-3">.col-6 .col-sm-3</div>
  4. <div class="col-6 col-sm-3">.col-6 .col-sm-3</div>
  5. <!-- Force next columns to break to new line -->
  6. <div class="w-100"></div>
  7. <div class="col-6 col-sm-3">.col-6 .col-sm-3</div>
  8. <div class="col-6 col-sm-3">.col-6 .col-sm-3</div>
  9. </div>
  10. </div>

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

Columns - 图6

  1. <div class="container">
  2. <div class="row">
  3. <div class="col-6 col-sm-4">.col-6 .col-sm-4</div>
  4. <div class="col-6 col-sm-4">.col-6 .col-sm-4</div>
  5. <!-- Force next columns to break to new line at md breakpoint and up -->
  6. <div class="w-100 d-none d-md-block"></div>
  7. <div class="col-6 col-sm-4">.col-6 .col-sm-4</div>
  8. <div class="col-6 col-sm-4">.col-6 .col-sm-4</div>
  9. </div>
  10. </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.

Columns - 图7

  1. <div class="container">
  2. <div class="row">
  3. <div class="col">
  4. First in DOM, no order applied
  5. </div>
  6. <div class="col order-5">
  7. Second in DOM, with a larger order
  8. </div>
  9. <div class="col order-1">
  10. Third in DOM, with an order of 1
  11. </div>
  12. </div>
  13. </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.

Columns - 图8

  1. <div class="container">
  2. <div class="row">
  3. <div class="col order-last">
  4. First in DOM, ordered last
  5. </div>
  6. <div class="col">
  7. Second in DOM, unordered
  8. </div>
  9. <div class="col order-first">
  10. Third in DOM, ordered first
  11. </div>
  12. </div>
  13. </div>

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-4 moves .col-md-4 over four columns.

Columns - 图9

  1. <div class="container">
  2. <div class="row">
  3. <div class="col-md-4">.col-md-4</div>
  4. <div class="col-md-4 offset-md-4">.col-md-4 .offset-md-4</div>
  5. </div>
  6. <div class="row">
  7. <div class="col-md-3 offset-md-3">.col-md-3 .offset-md-3</div>
  8. <div class="col-md-3 offset-md-3">.col-md-3 .offset-md-3</div>
  9. </div>
  10. <div class="row">
  11. <div class="col-md-6 offset-md-3">.col-md-6 .offset-md-3</div>
  12. </div>
  13. </div>

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

Columns - 图10

  1. <div class="container">
  2. <div class="row">
  3. <div class="col-sm-5 col-md-6">.col-sm-5 .col-md-6</div>
  4. <div class="col-sm-5 offset-sm-2 col-md-6 offset-md-0">.col-sm-5 .offset-sm-2 .col-md-6 .offset-md-0</div>
  5. </div>
  6. <div class="row">
  7. <div class="col-sm-6 col-md-5 col-lg-6">.col-sm-6 .col-md-5 .col-lg-6</div>
  8. <div class="col-sm-6 col-md-5 offset-md-2 col-lg-6 offset-lg-0">.col-sm-6 .col-md-5 .offset-md-2 .col-lg-6 .offset-lg-0</div>
  9. </div>
  10. </div>

Margin utilities

With the move to flexbox in v4, you can use margin utilities like .me-auto to force sibling columns away from one another.

Columns - 图11

  1. <div class="container">
  2. <div class="row">
  3. <div class="col-md-4">.col-md-4</div>
  4. <div class="col-md-4 ms-auto">.col-md-4 .ms-auto</div>
  5. </div>
  6. <div class="row">
  7. <div class="col-md-3 ms-md-auto">.col-md-3 .ms-md-auto</div>
  8. <div class="col-md-3 ms-md-auto">.col-md-3 .ms-md-auto</div>
  9. </div>
  10. <div class="row">
  11. <div class="col-auto me-auto">.col-auto .me-auto</div>
  12. <div class="col-auto">.col-auto</div>
  13. </div>
  14. </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.

Columns - 图12

  1. <div class="col-3 bg-light p-3 border">
  2. .col-3: width of 25%
  3. </div>
  4. <div class="col-sm-9 bg-light p-3 border">
  5. .col-sm-9: width of 75% above sm breakpoint
  6. </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.

Columns - 图13

  1. <div class="clearfix">
  2. <img src="..." class="col-md-6 float-md-end mb-3 ms-md-3" alt="...">
  3. <p>
  4. A paragraph of placeholder text. We're using it here to show the use of the clearfix class. We're adding quite a few meaningless phrases here to demonstrate how the columns interact here with the floated image.
  5. </p>
  6. <p>
  7. As you can see the paragraphs gracefully wrap around the floated image. Now imagine how this would look with some actual content in here, rather than just this boring placeholder text that goes on and on, but actually conveys no tangible information at. It simply takes up space and should not really be read.
  8. </p>
  9. <p>
  10. And yet, here you are, still persevering in reading this placeholder text, hoping for some more insights, or some hidden easter egg of content. A joke, perhaps. Unfortunately, there's none of that here.
  11. </p>
  12. </div>