Aral Code

Layout Lesson 3 of 12

Bootstrap Grid System — Containers, Rows and Columns

Build layouts with Bootstrap's 12-column grid — containers, rows and col classes, column widths, gutters, nesting and alignment.

Bootstrap's grid divides the width of the page into 12 columns. You build layouts by saying how many of those 12 columns each piece of content should take. It's built on Flexbox, which you learned in the CSS course.

The three parts

  1. Container: wraps everything and centers it.
  2. Row: a horizontal group of columns.
  3. Columns: the actual content boxes, inside rows.
Example Equal columns
<link rel="stylesheet" href="/vendor/bootstrap.min.css">
<style>.col { background: #e3f1ec; border: 1px solid #9cc9b8; padding: 12px; }</style>
<div class="container py-3">
  <div class="row">
    <div class="col">Math</div>
    <div class="col">Science</div>
    <div class="col">English</div>
  </div>
</div>

Plain col columns share the row equally. Add a fourth and they all shrink to fit.

Column widths

col-4 means "4 of the 12 columns". The numbers in a row should add up to 12:

Example Widths that add up to 12
<link rel="stylesheet" href="/vendor/bootstrap.min.css">
<style>[class*="col-"] { background: #fdf3dc; border: 1px solid #e2c27a; padding: 10px; }</style>
<div class="container py-3">
  <div class="row mb-2">
    <div class="col-8">col-8 (main content)</div>
    <div class="col-4">col-4 (sidebar)</div>
  </div>
  <div class="row mb-2">
    <div class="col-6">col-6</div>
    <div class="col-3">col-3</div>
    <div class="col-3">col-3</div>
  </div>
  <div class="row">
    <div class="col-12">col-12 (full width)</div>
  </div>
</div>
ClassWidth
col-12100%
col-650%
col-433.3%
col-325%
col-autoAs wide as its content

If the numbers add up to more than 12, the extra columns wrap to a new line.

Gutters

The space between columns is called the gutter. Change it with g-0 to g-5 on the row:

Example Gutters and card-like columns
<link rel="stylesheet" href="/vendor/bootstrap.min.css">
<div class="container py-3">
  <div class="row g-3">
    <div class="col-4"><div class="p-3 border bg-light">Box 1</div></div>
    <div class="col-4"><div class="p-3 border bg-light">Box 2</div></div>
    <div class="col-4"><div class="p-3 border bg-light">Box 3</div></div>
  </div>
</div>

Put your styled box inside the column, as here. Styling the column itself makes the gutters look wrong.

Nesting

A column can contain another row:

Example A nested row
<link rel="stylesheet" href="/vendor/bootstrap.min.css">
<div class="container py-3">
  <div class="row">
    <div class="col-8 border p-2">
      Main area
      <div class="row mt-2">
        <div class="col-6"><div class="bg-info-subtle p-2">Nested 1</div></div>
        <div class="col-6"><div class="bg-info-subtle p-2">Nested 2</div></div>
      </div>
    </div>
    <div class="col-4 border p-2">Sidebar</div>
  </div>
</div>

Alignment

Because rows are flex containers, Flexbox utilities work on them:

Example Centering and spacing columns
<link rel="stylesheet" href="/vendor/bootstrap.min.css">
<div class="container py-3">
  <div class="row justify-content-center mb-3">
    <div class="col-4"><div class="p-2 bg-warning-subtle">Centered</div></div>
  </div>
  <div class="row justify-content-between align-items-center" style="height:80px; background:#f6f6f6">
    <div class="col-3"><div class="p-2 bg-success-subtle">Left</div></div>
    <div class="col-3"><div class="p-2 bg-success-subtle">Right</div></div>
  </div>
</div>

Container types

  • container: fixed maximum width that grows at each breakpoint.
  • container-fluid: always 100% wide.
  • container-md and similar: 100% wide until the given breakpoint.

Quick Quiz

Check what you learned. Walang grade ito, practice lang. 🙂

1. How many columns does the Bootstrap grid have?
2. What width is col-3?
3. What happens if columns in a row add up to more than 12?
4. What's the correct nesting order?

By Sir Reyel · Last updated 2026-12-04