BBS5 Grid Basic

Understand the Bootstrap 5 grid system.

BS5 Grid Basic

Bootstrap's grid system is built with flexbox and allows up to 12 columns across the page.

If you do not want to use all 12 columns individually, you can group the columns together to create wider columns:

  • The grid system is responsive, and the columns will re-arrange automatically depending on the screen size.
  • Make sure that the sum adds up to 12 or fewer (it is not required that you use all 12 available columns options).

Grid Classes

The Bootstrap 5 grid system has six classes:

  • .col- (extra small devices - screen width less than 576px)
  • .col-sm- (small devices - screen width equal to or greater than 576px)
  • .col-md- (medium devices - screen width equal to or greater than 768px)
  • .col-lg- (large devices - screen width equal to or greater than 992px)
  • .col-xl- (xlarge devices - screen width equal to or greater than 1200px)
  • .col-xxl- (xxlarge devices - screen width equal to or greater than 1400px)

Examples

Three Equal Columns

html/css

Three equal-width columns.

<div class="row">
  <div class="col">.col</div>
  <div class="col">.col</div>
  <div class="col">.col</div>
</div>

Responsive Columns

html/css

Four equal columns on small screens and up.

<div class="row">
  <div class="col-sm-3">.col-sm-3</div>
  <div class="col-sm-3">.col-sm-3</div>
  <div class="col-sm-3">.col-sm-3</div>
  <div class="col-sm-3">.col-sm-3</div>
</div>

Unequal Columns

html/css

Two columns with different widths (4 and 8).

<div class="row">
  <div class="col-sm-4">.col-sm-4</div>
  <div class="col-sm-8">.col-sm-8</div>
</div>

Setting One Column Width

html/css

Center column is 50% width, others auto-size.

<div class="row">
  <div class="col">1 of 3</div>
  <div class="col-6">2 of 3 (wider)</div>
  <div class="col">3 of 3</div>
</div>

Test Your Knowledge

1. Bootstrap's grid system allows up to how many columns?

2. Which class is used for medium devices?