Bootstrap 5 Grid System Explained With Layouts You Can Test

Understand Bootstrap 5 containers, rows, columns and breakpoints, build common page layouts, and prototype them live with Bootstrap components and icons.

Updated September 29, 2026 5 min read

Use the free Bootstrap PlaygroundBuild and test Bootstrap 5 layouts live with starter templates

Bootstrap has been the default starting point for admin panels, internal tools, landing pages and countless first websites for over a decade. Its grid system is the part everyone uses, and also the part that causes the most confusion: why a column wraps too early, why there is a horizontal scrollbar, or why col-md-6 does nothing on a phone.

This guide explains how the Bootstrap 5 grid works, from containers to breakpoints to gutters, shows the markup for layouts you will actually build, and walks through prototyping them with Bootstrap's components in a live editor.

The three layers of the grid

Every Bootstrap layout uses the same structure: container, row, column.

<div class="container">
  <div class="row">
    <div class="col-md-8">Main content</div>
    <div class="col-md-4">Sidebar</div>
  </div>
</div>
  • Container sets the maximum width and horizontal padding. .container has a fixed maximum width at each breakpoint, .container-fluid is always full width, and .container-md (and similar) is full width until that breakpoint.
  • Row is a flexbox wrapper that holds columns and handles the spacing between them with negative margins. Columns must be direct children of a row.
  • Column sets how many of the 12 grid tracks an element spans.

The grid has 12 columns because 12 divides evenly into halves, thirds, quarters and sixths.

Breakpoints and column classes

Bootstrap 5 is mobile-first. A class applies from its breakpoint upwards:

Infix Applies from Example
(none) 0px col-6
sm 576px col-sm-6
md 768px col-md-6
lg 992px col-lg-6
xl 1200px col-xl-6
xxl 1400px col-xxl-6

So col-md-8 means "span 8 of 12 columns from 768 pixels up". Below 768 pixels, with no smaller class, the column is full width and stacks. Combining classes gives different layouts per size:

<div class="row">
  <div class="col-12 col-sm-6 col-lg-3">Card</div>
  <div class="col-12 col-sm-6 col-lg-3">Card</div>
  <div class="col-12 col-sm-6 col-lg-3">Card</div>
  <div class="col-12 col-sm-6 col-lg-3">Card</div>
</div>

One card per row on phones, two on small tablets, four on large screens.

Auto and equal columns

A plain .col shares space equally with its siblings. .col-auto takes only as much width as its content. You can mix them: a fixed col-3 sidebar next to a .col that fills the rest.

Row columns shortcut

row-cols-* sets the column count on the row instead of on each child, which keeps card grids tidy:

<div class="row row-cols-1 row-cols-md-3 g-4">
  <div class="col">Plan A</div>
  <div class="col">Plan B</div>
  <div class="col">Plan C</div>
</div>

Gutters

The g-* classes (g-0 to g-5) control spacing between columns, with gx-* and gy-* for horizontal and vertical only. Use them instead of adding margins to columns, which breaks the width calculations.

Prototype with the Bootstrap Playground

Our Bootstrap Playground renders your HTML with Bootstrap preloaded, so components and grid classes work immediately.

  1. Open the Bootstrap Playground.
  2. Choose a Starter template: Starter page, Navbar + hero, Card grid or Sign-up form. Each gives you working markup to adapt.
  3. Edit the markup in the HTML tab. Bootstrap 5.3.3 CSS, the JavaScript bundle and Bootstrap Icons 1.11.3 are already included, so dropdowns, modals, collapsing navbars and <i class="bi bi-…"> icons all work.
  4. Add your own overrides in the Custom CSS tab, for example rounder buttons or brand colours.
  5. Switch between Full width, Tablet (768px) and Phone (375px) to see columns stack and the navbar collapse. Use Expand preview for large layouts.
  6. Watch the Console for errors from your scripts.
  7. Click Download to save bootstrap-page.html. It keeps the same CDN links, so it works when opened anywhere with an internet connection.

Common layouts

Centre content on the page

Use flexbox utilities rather than custom CSS:

<div class="d-flex justify-content-center align-items-center min-vh-100">
  <div class="card p-4">Centred card</div>
</div>

col-lg-3 for the sidebar and col-lg-9 for content gives a side-by-side layout on large screens and stacked sections below 992 pixels. Add order-lg-first or order-lg-last to control which appears first.

Offsetting a narrow column

col-md-6 offset-md-3 centres a half-width column, a classic pattern for login forms.

Other ways to work with Bootstrap

Copy the CDN links from Bootstrap's official documentation into an HTML file and open it in your browser. This is exactly what the downloaded playground file does, and it is fine for small sites.

npm and Sass

For real projects, install Bootstrap with npm and compile its Sass source. This lets you change variables such as colours, breakpoints and spacing, and import only the parts you use, producing a much smaller CSS file.

Utility-first alternatives

Tailwind CSS builds layouts from small utilities instead of ready-made components. Compare the approach in the Tailwind CSS Playground. If you only need layout, plain CSS flexbox or grid may be enough; the Flexbox Playground and CSS Grid Generator help you write it.

Pitfalls and troubleshooting

Horizontal scrollbar on the page

Rows have negative margins. Placing a .row directly inside <body> or another element without a container's padding causes overflow. Always wrap rows in a container.

Columns wrap unexpectedly

The column numbers in one row add up to more than 12, or you added padding or borders to a column that pushes it wider. Put extra styling on an inner element instead of the column itself.

JavaScript components do nothing

Dropdowns, modals and collapsing navbars need the Bootstrap JavaScript bundle, which includes Popper. Check that data-bs-toggle (with the bs prefix, new in version 5) is used rather than the old data-toggle.

Colours and theme

Bootstrap's colour utilities (text-primary, bg-success) are driven by CSS variables in 5.3. For choosing brand colours that still meet contrast requirements, look up values in HTML Color Codes.

Frequently asked questions

Why does Bootstrap use a 12-column grid?

Twelve divides evenly into 2, 3, 4 and 6, so halves, thirds, quarters and sixths all use whole numbers of columns.

What is the difference between container and container-fluid?

.container has a maximum width that steps up at each breakpoint, leaving margins on large screens. .container-fluid always spans the full width of the viewport.

Do I need jQuery for Bootstrap 5?

No. Bootstrap 5 dropped the jQuery dependency. Its JavaScript works with plain browser APIs.

Why does col-md-6 not work on my phone?

Classes apply from their breakpoint upwards. On a phone narrower than 768 pixels, col-md-6 has no effect and the column is full width. Add col-6 if you want two columns on phones too.

Can I use Bootstrap Icons in the playground?

Yes. Bootstrap Icons are preloaded, so an element like <i class="bi bi-check-circle"></i> displays the icon straight away.

Try it now: Bootstrap Playground

Loading tool…