Lesson 49 of 60 – Bootstrap Responsive Utilities
82%

Bootstrap Responsive Utilities

Bootstrap Responsive Utilities help you create websites that work properly on different screen sizes. Bootstrap uses a mobile-first approach, so you can build layouts for small screens first and then add classes for larger screens.

Note: Bootstrap responsive utilities use breakpoint prefixes such as sm, md, lg, xl, and xxl. A responsive utility generally applies at that breakpoint and above.

1. What Are Responsive Utilities?

Responsive utilities are Bootstrap classes that allow elements to change their appearance or behavior according to the viewport size.

They can be used to:

  • Show or hide elements.
  • Change display behavior.
  • Change Flexbox direction.
  • Change text alignment.
  • Control spacing at different breakpoints.
  • Create responsive layouts.
  • Adapt navigation and buttons to different screen sizes.

2. Bootstrap Is Mobile-First

Bootstrap follows a mobile-first design approach.

This means you normally write the default style for smaller screens first and then use breakpoint classes to change the layout for larger screens.

<div
class="d-flex
flex-column
flex-md-row">

    Content

</div>

Here, the layout starts as a column and becomes a row from the medium breakpoint and above.

3. Bootstrap Breakpoints

Bootstrap provides the following standard responsive breakpoints:

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

The xs breakpoint is the default base size and normally does not require an xs class prefix.

4. Responsive Display Utilities

Display utilities can be combined with breakpoints to show or hide elements.

<div
class="d-none d-md-block">

    Desktop Content

</div>

The element is hidden by default and displayed as a block from the medium breakpoint and above.

5. Mobile-Only Content

You can display content on smaller screens and hide it from the medium breakpoint upward.

<div
class="d-block d-md-none">

    Mobile Content

</div>

This is useful when a mobile interface needs different content or controls.

6. Desktop-Only Content

You can hide content by default and display it on larger screens.

<div
class="d-none d-lg-block">

    Desktop Navigation

</div>

The element becomes a block from the large breakpoint and above.

7. Responsive Flex Direction

Flexbox utilities can change direction at different breakpoints.

<div
class="d-flex
flex-column
flex-md-row">

    <div>
        One
    </div>

    <div>
        Two
    </div>

</div>

The items are stacked vertically on smaller screens and arranged horizontally from the medium breakpoint.

8. Responsive Text Alignment

Bootstrap provides responsive text alignment utilities.

<div
class="text-center text-md-start">

    Responsive Text

</div>

The text is centered by default and aligned to the start from the medium breakpoint and above.

9. Responsive Spacing

Spacing utilities can also use breakpoint prefixes.

<div
class="p-2 p-md-4">

    Responsive Padding

</div>

The element has smaller padding by default and larger padding from the medium breakpoint.

10. Responsive Margin

Margin utilities can be changed at different breakpoints.

<div
class="mt-2 mt-lg-5">

    Responsive Margin

</div>

The top margin starts smaller and becomes larger from the large breakpoint.

11. Responsive Gap

Gap utilities can also use responsive prefixes.

<div
class="d-flex
gap-2
gap-md-4">

    <div>One</div>
    <div>Two</div>

</div>

The gap is smaller by default and becomes larger from the medium breakpoint.

12. Responsive Grid Columns

Bootstrap's grid system is one of the most important tools for responsive layouts.

<div class="row">

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

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

</div>

Each column takes the full width on small screens and half the width from the medium breakpoint upward.

13. Responsive Three-Column Layout

You can create a responsive three-column layout using col-lg-4.

<div class="row g-4">

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

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

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

</div>

The layout can change from one column to two columns and then three columns as the viewport becomes wider.

14. Responsive Containers

Bootstrap provides responsive container classes.

<div class="container">

    Responsive Container

</div>


<div class="container-fluid">

    Full Width Container

</div>

The standard container changes its maximum width according to the viewport, while container-fluid remains full width.

15. Responsive Container Classes

Bootstrap also provides breakpoint-specific containers.

<div class="container-sm">
    Container Small
</div>

<div class="container-md">
    Container Medium
</div>

<div class="container-lg">
    Container Large
</div>

These containers become constrained at their corresponding breakpoints.

16. Responsive Images

The img-fluid class makes an image responsive.

<img
src="photo.jpg"
class="img-fluid"
alt="Responsive photo">

The image scales down within its containing block instead of overflowing it.

17. Responsive Navbar

Bootstrap's Navbar component can change its behavior at a specified breakpoint.

<nav
class="navbar
navbar-expand-lg
bg-body-tertiary">

    <div class="container">

        <a
        class="navbar-brand"
        href="#">

            My Website

        </a>

    </div>

</nav>

The navbar-expand-lg class controls when the navbar expands into its larger-screen layout.

18. Responsive Buttons

Buttons can be arranged differently at different viewport sizes by using Flexbox and responsive utilities.

<div
class="d-flex
flex-column
flex-sm-row
gap-2">

    <button class="btn btn-primary">
        Login
    </button>

    <button class="btn btn-success">
        Register
    </button>

</div>

The buttons are stacked on very small screens and arranged in a row from the small breakpoint.

19. Responsive Cards

Cards can become responsive by combining the Bootstrap grid with cards.

<div class="row g-4">


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

        <div class="card h-100">

            <div class="card-body">

                <h4>
                    HTML
                </h4>

                <p>
                    Learn HTML.
                </p>

            </div>

        </div>

    </div>


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

        <div class="card h-100">

            <div class="card-body">

                <h4>
                    CSS
                </h4>

                <p>
                    Learn CSS.
                </p>

            </div>

        </div>

    </div>


</div>

20. Responsive Visibility

Display utilities can be used to create different versions of content for different viewport sizes.

<div class="d-block d-md-none">

    Mobile Version

</div>


<div class="d-none d-md-block">

    Desktop Version

</div>

This can be useful when a mobile and desktop interface needs different structures.

21. Responsive Flex Alignment

Flex alignment utilities can also be changed at breakpoints.

<div
class="d-flex
justify-content-center
justify-content-md-between">

    <div>
        Logo
    </div>

    <div>
        Menu
    </div>

</div>

The content is centered by default and distributed between the available space from the medium breakpoint.

22. Responsive Order

Bootstrap Flexbox order utilities can change the visual order of items at different breakpoints.

<div class="d-flex">

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

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

</div>

The visual order changes at the medium breakpoint.

23. Responsive Positioning

Position-related utilities can be combined with responsive display utilities.

<div
class="position-relative">


    <span
    class="position-absolute
    top-0
    end-0
    d-none d-md-block">

        Desktop Badge

    </span>


</div>

The badge is hidden on smaller screens and displayed from the medium breakpoint.

24. Responsive Tables

The table-responsive utility helps tables fit within small screens by allowing horizontal scrolling when necessary.

<div class="table-responsive">

    <table class="table">

        <thead>

            <tr>
                <th>Name</th>
                <th>Course</th>
                <th>Fee</th>
            </tr>

        </thead>

        <tbody>

            <tr>
                <td>Rahul</td>
                <td>Bootstrap</td>
                <td>5000</td>
            </tr>

        </tbody>

    </table>

</div>

25. Responsive Text Wrapping

Responsive layouts should allow text to wrap naturally rather than forcing content to stay on one line.

<div class="text-wrap">

    This is responsive text
    that can wrap naturally.

</div>

Avoid unnecessary fixed widths that cause text to overflow on smaller screens.

26. Common Responsive Design Mistakes

Avoid these common mistakes:

  • Designing only for desktop screens.
  • Using fixed widths everywhere.
  • Forgetting the mobile-first approach.
  • Using too many breakpoint overrides.
  • Allowing tables or images to overflow small screens.
  • Using text that becomes too small on mobile devices.
  • Creating buttons that are difficult to tap.
  • Hiding important content unnecessarily.
  • Testing only one screen size.

27. Responsive Layout Best Practices

Follow these practices when creating responsive Bootstrap websites:

  • Start with the mobile layout.
  • Use Bootstrap's grid system.
  • Use responsive Flexbox utilities.
  • Use responsive spacing utilities.
  • Use responsive display classes when necessary.
  • Use img-fluid for responsive images.
  • Use table-responsive for wide tables.
  • Keep content readable on small screens.
  • Test your design at different viewport widths.

28. Responsive Course Layout

The following example creates a responsive course layout.

<div class="container py-4">

    <div class="row g-4">


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

            <div class="card h-100">

                <div class="card-body">

                    <h3>
                        HTML
                    </h3>

                    <p>
                        Learn HTML.
                    </p>

                    <button
                    class="btn btn-primary w-100">

                        Start

                    </button>

                </div>

            </div>

        </div>


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

            <div class="card h-100">

                <div class="card-body">

                    <h3>
                        CSS
                    </h3>

                    <p>
                        Learn CSS.
                    </p>

                    <button
                    class="btn btn-success w-100">

                        Start

                    </button>

                </div>

            </div>

        </div>


    </div>

</div>

29. Practical Responsive Header

A responsive header can use Flexbox utilities to change its layout.

<header
class="p-3
border-bottom">


    <div
    class="d-flex
    flex-column
    flex-md-row
    justify-content-between
    align-items-center
    gap-3">


        <h2 class="mb-0">

            Soopro Pathshala

        </h2>


        <div
        class="d-flex
        flex-column
        flex-sm-row
        gap-2">


            <a
            href="#"
            class="btn btn-primary">

                Courses

            </a>


            <a
            href="#"
            class="btn btn-success">

                Contact

            </a>


        </div>


    </div>


</header>

The header starts vertically on smaller screens and becomes horizontal from the medium breakpoint.

30. Complete Responsive Bootstrap Example

This complete example combines responsive containers, grid columns, Flexbox, spacing, buttons, and responsive visibility.

<section class="py-5">


    <div class="container">


        <div
        class="d-flex
        flex-column
        flex-lg-row
        justify-content-between
        align-items-center
        gap-4
        mb-5">


            <div class="text-center text-lg-start">

                <h1>

                    Learn Bootstrap

                </h1>


                <p>

                    Build responsive websites
                    easily with Bootstrap.

                </p>

            </div>


            <div
            class="d-flex
            flex-column
            flex-sm-row
            gap-2">


                <button
                class="btn btn-primary">

                    Start Course

                </button>


                <button
                class="btn btn-outline-secondary">

                    View Lessons

                </button>


            </div>


        </div>


        <div class="row g-4">


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


                <div
                class="card
                h-100
                shadow-sm">


                    <div
                    class="card-body
                    text-center">


                        <h3>
                            HTML
                        </h3>


                        <p>
                            Learn HTML basics.
                        </p>


                        <button
                        class="btn
                        btn-primary
                        w-100">

                            Learn

                        </button>


                    </div>


                </div>


            </div>


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


                <div
                class="card
                h-100
                shadow-sm">


                    <div
                    class="card-body
                    text-center">


                        <h3>
                            CSS
                        </h3>


                        <p>
                            Learn CSS basics.
                        </p>


                        <button
                        class="btn
                        btn-success
                        w-100">

                            Learn

                        </button>


                    </div>


                </div>


            </div>


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


                <div
                class="card
                h-100
                shadow-sm">


                    <div
                    class="card-body
                    text-center">


                        <h3>
                            Bootstrap
                        </h3>


                        <p>
                            Learn Bootstrap.
                        </p>


                        <button
                        class="btn
                        btn-info
                        w-100">

                            Learn

                        </button>


                    </div>


                </div>


            </div>


        </div>


    </div>


</section>

Learn Bootstrap

Build responsive websites easily with Bootstrap.

HTML

Learn HTML basics.

CSS

Learn CSS basics.

Bootstrap

Learn Bootstrap.

📌 Key Points

  • Bootstrap uses a mobile-first responsive approach.
  • Standard breakpoints include sm, md, lg, xl, and xxl.
  • sm starts at 576px.
  • md starts at 768px.
  • lg starts at 992px.
  • xl starts at 1200px.
  • xxl starts at 1400px.
  • Responsive display classes can show or hide elements at different breakpoints.
  • Responsive Flexbox classes can change direction and alignment.
  • Responsive text utilities can change text alignment.
  • Responsive spacing utilities can change margin and padding.
  • Bootstrap's grid system is designed for responsive layouts.
  • img-fluid helps images fit within their containing block.
  • table-responsive helps wide tables work on small screens.
  • Responsive utilities are normally applied from their specified breakpoint and above.
  • Start with the mobile layout and enhance it for larger screens.
  • Avoid unnecessary fixed widths.
  • Always test layouts at different viewport sizes.

🧠 Quick Quiz

Question: Which Bootstrap breakpoint starts at 768px?