Bootstrap Grid System

The grid system is the most important part of Bootstrap. It uses a 12 column layout and flexbox to make responsive pages. You divide the width of the row in up to 12 parts, and say how many parts each column takes.

The structure

  • A .container (or .container-fluid) is the outer wrapper.
  • A .row goes inside it. It makes a flex row, and removes the side padding problems.
  • Columns .col go inside the row. Their total should be 12 or less in one line. More than 12 wraps in the next line.

Equal width columns

<div class="container text-center">
  <div class="row">
    <div class="col border bg-light py-2">Column</div>
    <div class="col border bg-light py-2">Column</div>
    <div class="col border bg-light py-2">Column</div>
  </div>
</div>
Live preview

The class .col without a number divides the row equally between all the columns.

Column sizes with numbers

<div class="container text-center">
  <div class="row mb-2">
    <div class="col-4 border bg-light py-2">col-4</div>
    <div class="col-8 border bg-light py-2">col-8</div>
  </div>
  <div class="row mb-2">
    <div class="col-3 border bg-light py-2">col-3</div>
    <div class="col-6 border bg-light py-2">col-6</div>
    <div class="col-3 border bg-light py-2">col-3</div>
  </div>
  <div class="row">
    <div class="col-12 border bg-light py-2">col-12 (full row)</div>
  </div>
</div>
Live preview

Responsive columns with breakpoints

You can add a breakpoint to the class: col-sm-*, col-md-*, col-lg-*, col-xl-* and col-xxl-*. The rule works from that screen width and up. Smaller screens get the full width (stacked).

ClassMeaning
col-66 of 12 columns on all screen sizes
col-md-6Stacked on small screens, 6 of 12 from 768px and up
col-12 col-md-6 col-lg-4Full width on phones, half on tablets, one third on big screens
<div class="container text-center">
  <div class="row">
    <div class="col-12 col-md-6 col-lg-4 mb-2"><div class="border bg-light py-3">1</div></div>
    <div class="col-12 col-md-6 col-lg-4 mb-2"><div class="border bg-light py-3">2</div></div>
    <div class="col-12 col-md-12 col-lg-4 mb-2"><div class="border bg-light py-3">3</div></div>
  </div>
</div>
Live preview

The preview is narrow, so the columns are stacked. Open this page on a big screen to see the three columns side by side.

The breakpoints

NamePrefixStarts at
Extra small(no prefix)0
Smallsm576px
Mediummd768px
Largelg992px
Extra largexl1200px
Extra extra largexxl1400px

Mobile first

Bootstrap is mobile first. A class without a breakpoint (like col-6) is used on all screens. A class with a breakpoint (like col-md-6) is used from that size and up. So start with the small screen, and add the changes for the bigger screens.

One column fills the rest

<div class="container text-center">
  <div class="row">
    <div class="col-3 border bg-light py-2">col-3</div>
    <div class="col border bg-light py-2">col (takes the rest)</div>
  </div>
</div>
Live preview

Common mistakes

  • Putting columns directly in a container, without a row.
  • Using more than 12 columns in a row on purpose, and not knowing why they wrap.
  • Forgetting the mobile layout. Always check the page on a small screen.
Note: The grid also uses gutters (spacing between the columns), which you can control. See Grid: Gutters, Offset and Order. Next: Grid: Gutters, Offset and Order.

Congratulations! Chapter Finished. Learn more about the similar topics:
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.