Lesson 11 of 60 – Responsive Grid
18%

Bootstrap Responsive Grid

The Bootstrap Responsive Grid allows you to create layouts that automatically adjust according to the screen size. You can control the number of columns displayed on mobile phones, tablets, laptops, and larger screens using Bootstrap's responsive column classes.

Bootstrap follows a mobile-first approach. This means you normally design the smallest-screen layout first and then add breakpoint-specific classes for larger screens.

Note: Bootstrap's grid is based on 12 columns. Responsive classes such as col-sm-6, col-md-4, and col-lg-3 allow the layout to change at different viewport sizes.

1. What is a Responsive Grid?

A responsive grid is a layout that changes its structure according to the available screen width.

For example, three columns can appear side by side on a desktop while the same columns can stack vertically on a mobile phone.

Desktop:
[ Column 1 ][ Column 2 ][ Column 3 ]

Mobile:
[ Column 1 ]
[ Column 2 ]
[ Column 3 ]

2. Bootstrap Uses Mobile-First Design

Bootstrap uses a mobile-first responsive approach. Base classes are applied first, and breakpoint classes are used to change the layout for larger screens.

<div class="col-12 col-md-6">
    Content
</div>

Here, the element is full width by default and becomes half width from the medium breakpoint upward.

3. Bootstrap Responsive Breakpoints

Bootstrap provides these standard responsive breakpoints:

  • xs: below 576px — no class prefix
  • sm: 576px and above
  • md: 768px and above
  • lg: 992px and above
  • xl: 1200px and above
  • xxl: 1400px and above

These breakpoint names are based on viewport width, not on particular physical devices.

4. Basic Responsive Column

A common responsive grid pattern is col-12 col-md-6.

<div class="row">

    <div class="col-12 col-md-6">
        Content
    </div>

    <div class="col-12 col-md-6">
        Content
    </div>

</div>

The columns are full width on smaller screens and half width from the medium breakpoint upward.

5. col-sm-6

The col-sm-6 class makes the column use 6 of 12 columns from the small breakpoint upward.

<div class="col-sm-6">
    Content
</div>

Below the small breakpoint, the column behaves as a full-width column unless another base column class changes that behavior.

6. col-md-4

The col-md-4 class makes a column use 4 of 12 columns from the medium breakpoint upward.

<div class="col-md-4">
    Course
</div>

This is commonly used for three-column layouts on larger screens.

7. Three Responsive Columns

Three columns can stack on smaller screens and appear side by side on medium and larger screens.

<div class="row">

    <div class="col-12 col-md-4">
        Box 1
    </div>

    <div class="col-12 col-md-4">
        Box 2
    </div>

    <div class="col-12 col-md-4">
        Box 3
    </div>

</div>

8. Four Responsive Columns

Four columns can be displayed on large screens by using col-lg-3.

<div class="row">

    <div class="col-12 col-lg-3">
        1
    </div>

    <div class="col-12 col-lg-3">
        2
    </div>

    <div class="col-12 col-lg-3">
        3
    </div>

    <div class="col-12 col-lg-3">
        4
    </div>

</div>

9. Different Widths at Different Breakpoints

You can give an element different column widths at different viewport sizes.

<div class="col-12 col-sm-6 col-lg-4">
    Course
</div>
  • Default → 12 columns
  • Small and above → 6 columns
  • Large and above → 4 columns

10. Understanding col-md-6

A very common beginner mistake is thinking that col-md-6 means half width only on medium screens.

In reality, it applies from the medium breakpoint and upward until another rule overrides it.

<div class="col-md-6">
    Content
</div>

So it is half width at medium, large, extra-large, and extra-extra-large viewport widths.

11. Mobile Full Width and Desktop Half Width

Use col-12 col-md-6 when you want one column per row on smaller screens and two columns per row on larger screens.

<div class="row">

    <div class="col-12 col-md-6">
        Left Content
    </div>

    <div class="col-12 col-md-6">
        Right Content
    </div>

</div>

12. Mobile Full Width and Desktop Third Width

Use col-12 col-lg-4 for three columns on large screens.

<div class="row">

    <div class="col-12 col-lg-4">
        Box 1
    </div>

    <div class="col-12 col-lg-4">
        Box 2
    </div>

    <div class="col-12 col-lg-4">
        Box 3
    </div>

</div>

13. Responsive Course Cards

A course website can use responsive columns to display cards according to the available screen width.

<div class="row g-4">

    <div class="col-12 col-md-6 col-lg-4">
        HTML Course
    </div>

    <div class="col-12 col-md-6 col-lg-4">
        CSS Course
    </div>

    <div class="col-12 col-md-6 col-lg-4">
        JavaScript Course
    </div>

</div>

This creates one column by default, two columns from medium and three columns from large.

14. Responsive Sidebar Layout

A responsive website can use a full-width content area on smaller screens and a main-content/sidebar layout on larger screens.

<div class="row">

    <main class="col-12 col-lg-8">
        Main Content
    </main>

    <aside class="col-12 col-lg-4">
        Sidebar
    </aside>

</div>

On smaller screens both sections take the full width. From the large breakpoint upward, the main content uses 8 columns and the sidebar uses 4.

15. Responsive Form Layout

Responsive grid classes are useful for creating forms that adapt to different screen sizes.

<div class="row">

    <div class="col-12 col-md-6">

        <label class="form-label">
            First Name
        </label>

        <input
        type="text"
        class="form-control">

    </div>

    <div class="col-12 col-md-6">

        <label class="form-label">
            Last Name
        </label>

        <input
        type="text"
        class="form-control">

    </div>

</div>

16. Responsive Image Gallery

The responsive grid is useful for image galleries.

<div class="row g-3">

    <div class="col-6 col-md-4 col-lg-3">
        <img
        src="image1.jpg"
        class="img-fluid"
        alt="Image 1">
    </div>

    <div class="col-6 col-md-4 col-lg-3">
        <img
        src="image2.jpg"
        class="img-fluid"
        alt="Image 2">
    </div>

    <div class="col-6 col-md-4 col-lg-3">
        <img
        src="image3.jpg"
        class="img-fluid"
        alt="Image 3">
    </div>

    <div class="col-6 col-md-4 col-lg-3">
        <img
        src="image4.jpg"
        class="img-fluid"
        alt="Image 4">
    </div>

</div>

This example creates two columns by default, three from medium, and four from large.

17. Responsive Navigation Layout

Responsive grid classes can also help arrange navigation-related content.

<div class="row">

    <div class="col-12 col-md-8">
        Website Logo
    </div>

    <div class="col-12 col-md-4">
        Navigation
    </div>

</div>

The sections stack on smaller screens and sit beside each other from the medium breakpoint upward.

18. Responsive Dashboard Cards

Dashboard statistics can be displayed using responsive columns.

<div class="row g-4">

    <div class="col-12 col-sm-6 col-lg-3">
        Total Students
    </div>

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

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

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

</div>

The layout changes from one column to two and then four columns as the viewport becomes wider.

19. Responsive Grid with g-4

The g-4 utility can be combined with responsive columns to create consistent spacing.

<div class="row g-4">

    <div class="col-12 col-md-6">
        Box 1
    </div>

    <div class="col-12 col-md-6">
        Box 2
    </div>

</div>

The responsive columns control the layout, while g-4 controls the gutter spacing.

20. Responsive Grid and Equal Heights

When cards in responsive columns should stretch to equal heights, you can use the h-100 utility on the cards.

<div class="row g-4">

    <div class="col-md-4">

        <div class="card h-100">

            <div class="card-body">
                Course 1
            </div>

        </div>

    </div>

    <div class="col-md-4">

        <div class="card h-100">

            <div class="card-body">
                Course 2
            </div>

        </div>

    </div>

</div>

21. Responsive Grid with xl

You can use the xl breakpoint when a layout should change at extra-large viewport widths.

<div class="col-12 col-xl-3">
    Box
</div>

The element is full width by default and uses 3 of 12 columns from the extra-large breakpoint upward.

22. Responsive Grid with xxl

The xxl breakpoint can be used when a layout needs a different arrangement on very wide screens.

<div class="col-12 col-xxl-3">
    Box
</div>

The col-xxl-3 rule applies from the xxl breakpoint upward.

23. Responsive Grid with Multiple Rules

You can combine several breakpoint rules in one class list.

<div class="col-12
            col-sm-6
            col-md-4
            col-lg-3">

    Product

</div>
  • Default → 12 columns
  • sm → 6 columns
  • md → 4 columns
  • lg → 3 columns

24. Responsive Grid with Offset

Bootstrap also provides responsive offset classes that can move a column to the right by a specified number of grid columns.

<div class="row">

    <div class="col-md-6 offset-md-3">
        Centered Content
    </div>

</div>

Here, the 6-column element has a 3-column offset from the medium breakpoint upward.

25. Responsive Grid and Order

Bootstrap provides responsive order utilities that can change the visual order of flex items.

<div class="row">

    <div class="col order-2 order-md-1">
        Main Content
    </div>

    <div class="col order-1 order-md-2">
        Sidebar
    </div>

</div>

The visual order can therefore be different at different breakpoints.

26. Responsive Grid and Alignment

Responsive grid layouts can be combined with Bootstrap's alignment utilities.

<div class="row
align-items-center">

    <div class="col-md-6">
        Content
    </div>

    <div class="col-md-6">
        Content
    </div>

</div>

Because Bootstrap rows use Flexbox, Flexbox utilities can be used to control alignment.

27. Responsive Grid Best Practices

  • Start with a mobile-friendly base layout.
  • Add breakpoint classes only when the layout needs to change.
  • Use col-12 for full-width mobile sections when needed.
  • Use col-md-6 for two-column medium-and-up layouts.
  • Use col-lg-4 for three-column large-and-up layouts.
  • Use gutters to maintain consistent spacing.
  • Test the layout at different viewport widths.

28. Common Responsive Grid Mistakes

  • Thinking col-md-6 applies only at the md breakpoint.
  • Forgetting the mobile-first behavior.
  • Using too many breakpoint classes without a clear reason.
  • Ignoring content overflow inside columns.
  • Forgetting to test intermediate viewport sizes.
  • Using column combinations that do not produce the intended layout.
  • Ignoring gutter spacing.

29. Responsive Grid Layout Planning

Before creating a responsive layout, decide how many columns should be visible at different viewport sizes.

Viewport Example Layout
Small screens 1 column
Medium screens 2 columns
Large screens 3 columns
Extra-large screens 4 columns

This planning approach helps you select suitable Bootstrap column classes before writing the HTML.

30. Complete Responsive Grid Example

<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta
    name="viewport"
    content="width=device-width,
    initial-scale=1.0">

    <title>
        Responsive Bootstrap Grid
    </title>

    <link
    href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"
    rel="stylesheet">

</head>

<body>

<div class="container py-5">

    <h1 class="text-center mb-4">
        Our Courses
    </h1>

    <div class="row g-4">

        <div class="col-12 col-sm-6 col-lg-4">

            <div class="card h-100">

                <div class="card-body">

                    <h5>
                        HTML Course
                    </h5>

                    <p>
                        Learn HTML from basic to advanced concepts.
                    </p>

                    <button
                    class="btn btn-primary">
                        Learn More
                    </button>

                </div>

            </div>

        </div>

        <div class="col-12 col-sm-6 col-lg-4">

            <div class="card h-100">

                <div class="card-body">

                    <h5>
                        CSS Course
                    </h5>

                    <p>
                        Learn CSS and responsive web design.
                    </p>

                    <button
                    class="btn btn-success">
                        Learn More
                    </button>

                </div>

            </div>

        </div>

        <div class="col-12 col-sm-6 col-lg-4">

            <div class="card h-100">

                <div class="card-body">

                    <h5>
                        Bootstrap Course
                    </h5>

                    <p>
                        Learn responsive layouts with Bootstrap.
                    </p>

                    <button
                    class="btn btn-danger">
                        Learn More
                    </button>

                </div>

            </div>

        </div>

    </div>

</div>

<script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js">
</script>

</body>

</html>

In this example, each course is full width by default, uses half of the row from the small breakpoint, and uses four columns from the large breakpoint upward.

📌 Key Points

  • Bootstrap uses a mobile-first responsive grid.
  • The grid is based on 12 columns.
  • Responsive classes use breakpoint names such as sm, md, lg, xl, and xxl.
  • There is no xs class prefix; the base class applies below the sm breakpoint.
  • col-md-6 means 6 columns from the md breakpoint upward.
  • col-12 col-md-6 creates a full-width mobile layout and a half-width md-and-up layout.
  • Multiple breakpoint classes can be combined.
  • Responsive grids are useful for cards, forms, dashboards, galleries, sidebars, and complete websites.
  • Offset and order utilities can also be used with responsive layouts.
  • Always test responsive layouts at different viewport widths.

🧠 Quick Quiz

Question: What does col-md-6 mean?