Bootstrap 5 CSS Grid
Bootstrap 5's CSS Grid system is an opt-in alternative to the standard flexbox-based grid, enabling two-dimensional layouts using native CSS Grid under the hood. It is activated by setting `display: grid` on a container with the `.grid` class and placing children using `g-col-*` utilities. Use it when you need precise row and column spanning, overlapping elements, or layouts that flexbox handles awkwardly.
Primary Class
.css-gridCommon Use Cases
- →Building a magazine-style editorial layout where the lead article spans two columns and the sidebar spans three rows alongside it
- →Creating a pricing page where the featured plan card visually breaks the row by spanning an extra column and using a different row height
- →Designing a dashboard with metric cards of varying widths — revenue card spans 8 columns, two KPI cards each span 2 — without nesting extra wrapper divs
- →Constructing a photo gallery with a hero image that spans both columns and rows while smaller thumbnails fill the remaining cells automatically
Variants & Classes
| Variant | Description |
|---|---|
| CSS Grid Default | Standard css grid with Bootstrap's default styling. |
| CSS Grid Responsive | Responsive variant that adapts to different screen sizes. |
Code Example
<div class="grid" style="--bs-columns: 12; --bs-gap: 1.5rem;">
<!-- Full-width page header -->
<div class="g-col-12">
<h1 class="mb-0">Product Catalogue</h1>
</div>
<!-- Sidebar: 3 columns wide -->
<aside class="g-col-12 g-col-md-3 p-3 bg-light rounded">
<h5>Filter by Category</h5>
<ul class="list-unstyled mb-0">
<li><a href="#">Running Shoes</a></li>
<li><a href="#">Trail Boots</a></li>
<li><a href="#">Sandals</a></li>
</ul>
</aside>
<!-- Main content: spans remaining 9 columns -->
<section class="g-col-12 g-col-md-9">
<div class="grid" style="--bs-columns: 3; --bs-gap: 1rem;">
<div class="g-col-1 card p-3">Trail Runner X2</div>
<div class="g-col-1 card p-3">Summit Boot Pro</div>
<div class="g-col-1 card p-3">Coastal Sandal</div>
</div>
</section>
<!-- Full-width footer strip -->
<footer class="g-col-12 text-muted small pt-2 border-top">
Showing 3 of 24 products
</footer>
</div>Live Examples
Basic CSS Grid
Canvas Framework Variants
The Canvas template extends Bootstrap 5 with 1,658+ component variants. Generate any of these using Canvas Builder:
- ✓Canvas Builder generated css grid with custom colours
- ✓CSS Grid with interactive states
- ✓Responsive css grid for all screen sizes
Best Practices
Override column count with a CSS variable, not a new class
Bootstrap's CSS Grid uses the `--bs-columns` custom property, so you can change the grid from 12 to 6 columns by adding `style="--bs-columns: 6"` inline or in a scoped CSS rule — no extra utility classes needed.
Use `g-start-*` to force a column start position
Apply `g-start-4` to make an element begin at column line 4 regardless of what precedes it — essential for pinning a sidebar to the right or creating deliberate whitespace gaps in an editorial layout.
Nest `.grid` containers for independent sub-grids
Place a second `.grid` div inside a `g-col-*` cell and set its own `--bs-columns` value; the child grid is completely independent, so a 9-column main area can host a 3-column product card row without inheriting the parent's column count.
Combine with responsive `g-col-{breakpoint}-*` classes
Stack everything to full-width on mobile with `g-col-12`, then apply `g-col-md-4` for tablet and `g-col-lg-3` for desktop — the same responsive breakpoint tokens from the flex grid work identically here.