Bootstrap 5: Mastering Media Queries

Ruth Jul 09, 2026

Bootstrap 5, the latest iteration of the popular CSS framework, has introduced a range of improvements and new features, with media queries being one of the most notable. Media queries in Bootstrap 5 allow for responsive design, enabling web developers to create dynamic and flexible layouts that adapt to different screen sizes and devices. In this article, we'll delve into the world of Bootstrap 5 media queries, exploring their syntax, usage, and best practices.

Bootstrap Media Queries and How to use it?
Bootstrap Media Queries and How to use it?

Before we dive into the specifics, let's briefly recap what media queries are. Media queries are a CSS technique used to apply styles based on the result of one or more media queries. They use media types and media features to determine whether a device's characteristics match the specified criteria, applying styles accordingly.

Bootstrap 5.3 (2025) Cheat Sheet
Bootstrap 5.3 (2025) Cheat Sheet

Understanding Bootstrap 5 Media Queries

Bootstrap 5 uses a mobile-first approach, meaning that your styles are applied starting from the smallest screen size and then overridden for larger screens. This ensures that your website is functional and styled appropriately on mobile devices first, with additional styles and layout adjustments being applied as the screen size increases.

Bootstrap Tutorial | Bootstrap Notes | Bootstrap 5
Bootstrap Tutorial | Bootstrap Notes | Bootstrap 5

Bootstrap 5 media queries are based on the viewport's width and use the following breakpoints: `xs` (extra small, less than 576px), `sm` (small, 576px and up), `md` (medium, 768px and up), `lg` (large, 992px and up), and `xl` (extra large, 1200px and up). These breakpoints can be customized if needed.

Syntax and Usage

40+ Best Free Bootstrap Templates & Themes in 2026 — Speckyboy
40+ Best Free Bootstrap Templates & Themes in 2026 — Speckyboy

Bootstrap 5 media queries are used in conjunction with the responsive utility classes. These classes are applied to elements to apply specific styles based on the screen size. The syntax for using these classes is simple: `class="d-{breakpoint}-{display}"`, where `{breakpoint}` is one of the Bootstrap 5 breakpoints (`xs`, `sm`, `md`, `lg`, `xl`), and `{display}` is one of the display values (`none`, `inline`, `inline-block`, `block`, `flex`, `inline-flex`, `table`, `table-cell`, `grid`, `inline-grid`).

For example, to hide an element on small screens and show it on medium and larger screens, you would use the following class: `class="d-md-block"`. This tells Bootstrap 5 to apply a `display: block;` style to the element when the viewport's width is at the medium breakpoint or larger.

Responsive Images and Embeds

Bootstrap 5 Website Layout Design
Bootstrap 5 Website Layout Design

Bootstrap 5 also provides utilities for making images and embeds responsive. The `.img-fluid` class applies `max-width: 100%;` and `height: auto;` to an image, scaling it down proportionally based on its parent element's size. The `.d-block` and `.d-inline-block` classes can be used to control the display property of images and embeds at different breakpoints, ensuring they are displayed appropriately regardless of the screen size.

For example, to make an image responsive and hide it on small screens, you would use the following classes: `class="img-fluid d-sm-block"`. This tells Bootstrap 5 to apply the responsive image styles and hide the image on small screens, displaying it on medium and larger screens.

Best Practices for Using Bootstrap 5 Media Queries

Bootstrap Tutorial | Bootstrap Notes | Bootstrap 5
Bootstrap Tutorial | Bootstrap Notes | Bootstrap 5

When using Bootstrap 5 media queries, it's essential to follow some best practices to ensure your website is responsive, performant, and easy to maintain. One key practice is to use the responsive utility classes sparingly and rely on custom CSS for more complex or specific styles. This helps keep your HTML clean and your CSS organized.

Another best practice is to test your website on various devices and screen sizes to ensure it behaves as expected. Bootstrap 5 includes a helpful tool called the Bootstrap Studio, which allows you to preview your website at different breakpoints and make adjustments as needed.

Bootstrap 5 Modal Form
Bootstrap 5 Modal Form
HOT GADGETS e-commerce web page
HOT GADGETS e-commerce web page
Bootstrap Tutorial | Bootstrap Notes | Bootstrap 5
Bootstrap Tutorial | Bootstrap Notes | Bootstrap 5
100+ Free Bootstrap 5 Templates » CSS Author
100+ Free Bootstrap 5 Templates » CSS Author
Webstrot Admin Panel Responsive Bootstrap Dashboard Template
Webstrot Admin Panel Responsive Bootstrap Dashboard Template
Bootstrap Themes at BootstrapZero
Bootstrap Themes at BootstrapZero
an image of a dashboard screen with different colors and numbers on it, as well as the
an image of a dashboard screen with different colors and numbers on it, as well as the
WebkitX Bootstrap 5 Admin Dashboard Template with LTR Mini Sidebar
WebkitX Bootstrap 5 Admin Dashboard Template with LTR Mini Sidebar
Bootstrap 5 Buttons with Icon and Text Tutorial & Demo — CodeHim
Bootstrap 5 Buttons with Icon and Text Tutorial & Demo — CodeHim
Bootstrap Photo Gallery
Bootstrap Photo Gallery
Ynex - Blazor Server Bootstrap Admin Template
Ynex - Blazor Server Bootstrap Admin Template
Premium Bootstrap 5 Admin Template | Azia Template
Premium Bootstrap 5 Admin Template | Azia Template
News Digest Code | Bootstrap 5.3 snippet for building newsletter layouts for the web
News Digest Code | Bootstrap 5.3 snippet for building newsletter layouts for the web
Responsive Bootstrap Website Start To Finish with Bootstrap 4, HTML5, CSS3 & jQuery
Responsive Bootstrap Website Start To Finish with Bootstrap 4, HTML5, CSS3 & jQuery
100+ Best Free Bootstrap Templates 2024
100+ Best Free Bootstrap Templates 2024
Chat bot Bootstrap 5 Admin Templates with LTR Light Theme
Chat bot Bootstrap 5 Admin Templates with LTR Light Theme
NeuBoard Responsive Admin Template Bootstrap + AngularJS
NeuBoard Responsive Admin Template Bootstrap + AngularJS
7 New Features to Look Out For in Bootstrap 5
7 New Features to Look Out For in Bootstrap 5
Bootstrap 5 tutorial - Learn how to get started without jQuery - Themesberg Blog
Bootstrap 5 tutorial - Learn how to get started without jQuery - Themesberg Blog
Elite Admin - Bootstrap 5 Dashboard template
Elite Admin - Bootstrap 5 Dashboard template

Customizing Breakpoints

While Bootstrap 5's default breakpoints are suitable for many projects, you may find that you need to customize them to better fit your specific needs. Bootstrap 5 allows you to customize the breakpoints by modifying the `$grid-breakpoints` variable in the source Sass files. This variable is an associative array that maps breakpoint names to their respective pixel values.

For example, to change the medium breakpoint from 768px to 800px, you would update the `$grid-breakpoints` variable like so: `$grid-breakpoints: (xs: 0, sm: 576px, md: 800px, lg: 992px, xl: 1200px);`. After making this change, recompile your Sass to apply the new breakpoints to your project.

Accessibility Considerations

When using media queries to apply styles based on screen size, it's crucial to consider accessibility. Not all users have the same screen resolution or use the same browser settings, so it's essential to ensure that your website is accessible to as many users as possible. One way to do this is to use media queries in conjunction with the `prefers-reduced-motion` media feature, which allows you to detect whether a user has requested that the system minimize the amount of non-essential motion it uses.

For example, to apply a style only to users who have enabled reduced motion, you would use the following media query: `@media (prefers-reduced-motion: reduce) { /* your styles here */ }`. This ensures that your website is accessible to users with motion sensitivities or those who prefer a less animated experience.

In the ever-evolving landscape of web development, Bootstrap 5's media queries provide a powerful and flexible toolset for creating responsive and engaging user experiences. By understanding the syntax, usage, and best practices of Bootstrap 5 media queries, you can harness their power to build websites that adapt to the diverse range of devices and screen sizes that users encounter today. So go forth, and create responsive designs that captivate and engage your audience!