Class 7 of 48 • Bootstrap Fundamentals

Bootstrap 5 Native CSS Grid: Architecture & Usage

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.

Bootstrap 5 Opt-in Native CSS Grid System with .grid and .g-col-*
Figure 7: Native CSS Grid architecture showing 12-column display: grid layout and fractional gap spacing.

How to Enable Native CSS Grid in Bootstrap 5

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";

Native CSS Grid Markup: .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>

Responsive Columns & Column Starts in CSS Grid

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>

Comparison: When to Use CSS Grid vs Flexbox Grid

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).

Explore Related Bootstrap Tutorials & Next Steps

Strengthen your responsive web design mastery by studying these connected classes:

Standard 12-Column Grid

Compare CSS Grid with the standard flexbox-based 12-column grid.

Enabling CSS Grid in Sass

Set $enable-cssgrid: true in your Sass configuration.

Flexbox Utilities Reference

Choose between CSS Grid and Flexbox for various UI patterns.

Bootstrap Layout Helpers

Master aspect ratios, vertical stacks (vstack), and horizontal stacks (hstack).

Frequently Asked Questions (FAQ) - Student & Interview Review

To ensure backward compatibility with millions of existing Bootstrap websites and to avoid adding unnecessary CSS filesize for developers who are completely satisfied with the traditional flexbox grid.
Yes! You can override the CSS custom property --bs-columns directly on the element (e.g. style='--bs-columns: 16;') or in Sass via $grid-columns: 16;.
In CSS Grid, offsets are replaced by .g-start-* classes (e.g. .g-start-4), which directly set the native CSS property grid-column-start.

Next Step in Your Bootstrap Learning Path:

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

Share Share on Facebook Share on Twitter Share on LinkedIn Pin on Pinterest Share on Reddit

You may also like this!