While Bootstrap's traditional grid relies on CSS Flexbox, Bootstrap 5 introduced an experimental, opt-in Native CSS Grid System. Built on CSS display: grid, this layout model eliminates the need for .row wrappers and allows you to create two-dimensional layouts where child elements flow seamlessly across both rows and columns.
Because the default compiled bootstrap.css ships with the flexbox grid, enabling native CSS Grid requires compiling Bootstrap via Sass with the $enable-cssgrid boolean flag:
/* In your custom.scss file before importing bootstrap */
$enable-cssgrid: true;
@import "bootstrap/scss/bootstrap";
.grid and .g-col-*Once enabled, you replace .row with .grid, and .col-* with .g-col-*:
<!-- Native CSS Grid Container -->
<div class="grid" style="--bs-columns: 12; --bs-gap: 1.5rem;">
<div class="g-col-6 bg-primary text-white p-3">Spans 6 Columns (50%)</div>
<div class="g-col-6 bg-success text-white p-3">Spans 6 Columns (50%)</div>
<div class="g-col-4 bg-info text-white p-3">Spans 4 Columns (33.33%)</div>
<div class="g-col-4 bg-warning text-dark p-3">Spans 4 Columns (33.33%)</div>
<div class="g-col-4 bg-danger text-white p-3">Spans 4 Columns (33.33%)</div>
</div>
Just like the flexbox grid, native CSS grid classes support responsive breakpoints (g-col-md-6) and starting position offsets via .g-start-*:
<div class="grid">
<!-- Starts at column 3, spans 6 columns -->
<div class="g-col-6 g-start-3 bg-light p-4 text-center shadow-sm">
<h4>Centered via Grid Placement</h4>
<p>Positioned from line 3 to 9 using .g-start-3 and .g-col-6.</p>
</div>
</div>
Use Flexbox Grid (standard .row & .col-*) for 1-dimensional layouts (navbars, card decks, forms, horizontal button groups). Use Native CSS Grid (.grid & .g-col-*) for complex 2-dimensional layouts (photo gallery masonry, magazine editorial layouts, dashboard widget grids).
Strengthen your responsive web design mastery by studying these connected classes:
Compare CSS Grid with the standard flexbox-based 12-column grid.
Set $enable-cssgrid: true in your Sass configuration.
Choose between CSS Grid and Flexbox for various UI patterns.
Master aspect ratios, vertical stacks (vstack), and horizontal stacks (hstack).
--bs-columns directly on the element (e.g. style='--bs-columns: 16;') or in Sass via $grid-columns: 16;.
.g-start-* classes (e.g. .g-start-4), which directly set the native CSS property grid-column-start.
Advance your practical frontend engineering skills with the next topic in our synchronized curriculum.
Continue to Class 8: Typography & Headings → Previous: ← Class 6: Grid Columns & Offsets | Full Syllabus