BS5 Grid System

Create responsive layouts with Bootstrap's powerful grid

šŸ“ What is the Grid System?

Bootstrap's grid system uses containers, rows, and columns to layout content. It's built with flexbox and is fully responsive. The grid divides the page into 12 columns, allowing flexible and powerful layouts for all screen sizes.


<!-- Basic Grid -->
<div class="container">
    <div class="row">
        <div class="col">Column 1</div>
        <div class="col">Column 2</div>
    </div>
</div>
                                    

Grid Basics

Bootstrap’s responsive grid system is built on a fundamental three-component structure: Containers (.container or .container-fluid), Rows (.row), and Columns (.col-*). Containers provide a max-width and horizontal padding, rows are flex containers that hold columns and negate the container’s padding via negative margins, and columns are the immediate children of rows where content resides. Adhering strictly to this hierarchy—containers wrap rows, rows wrap columns—is crucial for proper alignment, consistent gutters, and intended responsive behavior. This semantic, organized HTML foundation is highly favorable for SEO, as it creates a clean, logical document structure that search engine crawlers can easily parse and index.

šŸ”ø Equal Width Columns

<div class="container">
    <div class="row">
        <div class="col">Column 1</div>
        <div class="col">Column 2</div>
        <div class="col">Column 3</div>
    </div>
</div>

Output:

Column 1
Column 2
Column 3

šŸ”¹ Column Widths

Control layout proportions by assigning columns numeric values from 1 to 12, representing the number of grid units they should occupy out of the total 12. For instance, .col-6 takes half the width, .col-4 takes one-third, and .col-8 takes two-thirds. The sum of column numbers in a single row should ideally be 12 to fill the available space completely, but wrapping behavior accommodates other totals. This intuitive system allows for endless, precise layout combinations. Using these explicit width classes creates predictable, semantic layouts that improve content structure, which aids search engine understanding and contributes to a positive user experience—both important for SEO performance.

<div class="container">
    <div class="row">
        <div class="col-8">col-8 (wider)</div>
        <div class="col-4">col-4</div>
    </div>
    <div class="row">
        <div class="col-6">col-6</div>
        <div class="col-6">col-6</div>
    </div>
    <div class="row">
        <div class="col-4">col-4</div>
        <div class="col-4">col-4</div>
        <div class="col-4">col-4</div>
    </div>
</div>

Output:

col-8 (wider)
col-4
col-6
col-6
col-4
col-4
col-4

šŸ”¹ Responsive Breakpoints

Bootstrap 5’s responsive breakpoints are predefined media query ranges that enable adaptive, mobile-first design across all devices. The six default breakpoints are X-Small (`<576px`), Small (`≄576px`), Medium (`≄768px`), Large (`≄992px`), X-Large (`≄1200px`), and XX-Large (`≄1400px`). You apply breakpoint-specific classes by appending the breakpoint abbreviation (e.g., `-md`, `-lg`) to utility classes, like `col-md-6` or `text-lg-center`. This systematic approach ensures your design scales seamlessly from phones to desktops, providing optimal user experience on every screen size.

Breakpoint Sizes:

  • xs - <576px (default, no prefix needed)
  • sm - ≄576px (.col-sm-*)
  • md - ≄768px (.col-md-*)
  • lg - ≄992px (.col-lg-*)
  • xl - ≄1200px (.col-xl-*)
  • xxl - ≄1400px (.col-xxl-*)
<div class="container">
    <div class="row">
        <div class="col-12 col-md-6 col-lg-4">
            Full width on mobile, half on tablet, third on desktop
        </div>
        <div class="col-12 col-md-6 col-lg-4">
            Full width on mobile, half on tablet, third on desktop
        </div>
        <div class="col-12 col-md-12 col-lg-4">
            Full width on mobile and tablet, third on desktop
        </div>
    </div>
</div>

Output:

Full width on mobile, half on tablet, third on desktop
Full width on mobile, half on tablet, third on desktop
Full width on mobile and tablet, third on desktop

šŸ”¹ Nesting Columns

Achieve advanced layout complexity by nesting a new .row and column set inside an existing parent column, creating a subordinate 12-unit grid within it. This technique is essential for designing intricate interfaces like dashboards with widgetized areas, detailed product pages with multiple sections, or featured content grids. Each nested grid operates independently, allowing for precise internal control. It’s crucial to maintain semantic HTML structure and avoid excessive nesting depth to prevent performance issues. Well-executed nested grids create rich, organized content presentations that improve user engagement and time-on-site—valuable behavioral metrics that search engines consider when evaluating page quality and relevance.

<div class="container">
    <div class="row">
        <div class="col-8">
            Parent Column
            <div class="row">
                <div class="col-6">Nested 1</div>
                <div class="col-6">Nested 2</div>
            </div>
        </div>
        <div class="col-4">Sidebar</div>
    </div>
</div>

Output:

Parent Column
Nested 1
Nested 2
Sidebar

šŸ”¹ Column Offset

Create intentional whitespace or center content by pushing columns to the right using .offset-* classes, which apply left margin equal to the width of the specified number of columns. For example, .col-4 .offset-4 centers a 4-column wide element. Offsets provide a cleaner, more semantic alternative to using empty placeholder columns in your HTML. They are powerful for creating balanced, asymmetric designs without extra markup. This leads to cleaner code, faster page loads, and improved maintainability—all positive technical SEO factors. Proper use of whitespace also enhances content readability and user focus, contributing to a better overall user experience.

<div class="container">
    <div class="row">
        <div class="col-4">col-4</div>
        <div class="col-4 offset-4">col-4 offset-4</div>
    </div>
    <div class="row">
        <div class="col-6 offset-3">col-6 offset-3 (centered)</div>
    </div>
</div>

Output:

col-4
col-4 offset-4
col-6 offset-3 (centered)

šŸ”¹ Gutters (Spacing)

Precisely control the spacing (gutters) between columns using Bootstrap’s gap utility classes: .g-* (all sides), .gx-* (horizontal), and .gy-* (vertical), with scales from 0 to 5. These classes modify the CSS gap property on the parent .row. Consistent, adequate spacing improves visual hierarchy, readability, and the overall aesthetic of a layout, directly impacting user experience. From an SEO standpoint, using these utility classes instead of custom CSS reduces stylesheet bloat, improves page load speed (a critical ranking factor), and creates a more maintainable codebase. Well-spaced content is also more accessible and engaging, encouraging longer visit durations.

<!-- No gutters -->
<div class="row g-0">
    <div class="col-6">No gap</div>
    <div class="col-6">No gap</div>
</div>

<!-- Large gutters -->
<div class="row g-5">
    <div class="col-6">Large gap</div>
    <div class="col-6">Large gap</div>
</div>

Output:

No gap
No gap
Large gap
Large gap

🧠 Test Your Knowledge

How many columns does Bootstrap's grid system have?