Mastering Bootstrap: Media Queries for Min & Max Width

Ruth Jul 09, 2026

Media queries are a powerful tool in responsive web design, allowing us to apply different styles based on the size and type of device rendering our content. In Bootstrap, media queries are used extensively to create responsive layouts. Two of the most commonly used properties in Bootstrap's media queries are `min-width` and `max-width`, which help us target specific screen sizes. Let's dive into how these properties work and explore some practical examples.

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

Before we delve into the specifics, it's essential to understand that Bootstrap uses a mobile-first approach. This means that your styles are applied to smaller screens first, and then overridden or extended as the screen size increases. Media queries are used to apply these overrides and extensions.

Bootstrap 5 Website Layout Design
Bootstrap 5 Website Layout Design

Understanding min-width and max-width in Bootstrap

In Bootstrap, `min-width` and `max-width` are used to create breakpoints, which are specific screen sizes at which our styles change. These breakpoints are defined in the Bootstrap CSS and can be customized if needed. Let's explore how these properties work in more detail.

the different types of font and numbers
the different types of font and numbers

When using `min-width`, the styles inside the media query will only be applied when the screen's width is greater than or equal to the specified value. Conversely, `max-width` applies styles when the screen's width is less than or equal to the specified value.

Using min-width in Bootstrap

a screenshot of a computer screen with the text,'how do i use this?
a screenshot of a computer screen with the text,'how do i use this?

To use `min-width` in Bootstrap, you would typically use the following syntax:

.class-name { /* styles */ } @media (min-width: $breakpoint) { /* styles */ }

Here, `$breakpoint` is a variable that corresponds to one of Bootstrap's predefined breakpoints. For example, `$breakpoint` could be set to `576px` for the small screen breakpoint, `768px` for the medium screen breakpoint, and so on.

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

Let's say we want to make a div's background color red when the screen's width is 768px or greater. We could achieve this with the following code:

.example { background-color: red; } @media (min-width: 768px) { .example { background-color: blue; } }

In this example, the div with the class `example` will have a blue background on screens 768px wide and above, and a red background on smaller screens.

Bootstrap 3 grid system explained
Bootstrap 3 grid system explained

Using max-width in Bootstrap

Using `max-width` in Bootstrap follows a similar syntax:

the diagram shows different types of electronic devices and their features, including laptops, tablets, phones, and more
the diagram shows different types of electronic devices and their features, including laptops, tablets, phones, and more
Bootstrap Tutorial | Bootstrap Notes | Bootstrap 5
Bootstrap Tutorial | Bootstrap Notes | Bootstrap 5
Bootstrap Tutorial | Bootstrap Notes | Bootstrap 5
Bootstrap Tutorial | Bootstrap Notes | Bootstrap 5
How To Center a div Horizontally in Bootstrap 4
How To Center a div Horizontally in Bootstrap 4
Bootstrap Tutorial | Bootstrap Notes | Bootstrap 5
Bootstrap Tutorial | Bootstrap Notes | Bootstrap 5
Using Media Queries For Responsive Design In 2018 — Smashing Magazine
Using Media Queries For Responsive Design In 2018 — Smashing Magazine
Bootstrap Tutorial | Bootstrap Notes | Bootstrap 5
Bootstrap Tutorial | Bootstrap Notes | Bootstrap 5
Spaner - Bootstrap Admin Panel Dashboard Design Responsive HTML5 Template
Spaner - Bootstrap Admin Panel Dashboard Design Responsive HTML5 Template
Bootstrap Tutorial | Bootstrap Notes | Bootstrap 5
Bootstrap Tutorial | Bootstrap Notes | Bootstrap 5
an info board with different types of information and symbols on the front, including text
an info board with different types of information and symbols on the front, including text
Bootstrap 4 Tutorial: Create a One-Page Template
Bootstrap 4 Tutorial: Create a One-Page Template
How the Bootstrap 4 Grid Works
How the Bootstrap 4 Grid Works
Bootstrap 5 Modal Form
Bootstrap 5 Modal Form
Qixa Admin Template
Qixa Admin Template
Understanding the Bootstrap 4 Grid System
Understanding the Bootstrap 4 Grid System
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
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
Bootstrap 4: What’s New
Bootstrap 4: What’s New
Geeks Bootstrap UI Kit and Admin Dashboard Template
Geeks Bootstrap UI Kit and Admin Dashboard Template
Intellir - Responsive Bootstrap 4 Admin Dashboard Template
Intellir - Responsive Bootstrap 4 Admin Dashboard Template

.class-name { /* styles */ } @media (max-width: $breakpoint) { /* styles */ }

Let's say we want to hide a div when the screen's width is 992px or less. We could achieve this with the following code:

.example { display: block; } @media (max-width: 992px) { .example { display: none; } }

In this case, the div with the class `example` will be hidden on screens 992px wide and below, and visible on larger screens.

Responsive Images with min-width and max-width

Another common use case for `min-width` and `max-width` is creating responsive images. By using these properties, we can ensure that our images scale nicely with the screen size without distorting their aspect ratio.

Bootstrap provides a class called `.img-fluid` that can be used to make images responsive. However, if you need more control over your image's behavior, you can use `min-width` and `max-width` directly. Here's an example:

<img src="example.jpg" style="max-width: 100%; height: auto;">

In this example, the image will scale down to fit the width of its container while maintaining its aspect ratio. The `height: auto;` style ensures that the image's height is adjusted automatically to preserve its aspect ratio.

Using min-width and max-width together

In some cases, you might want to use `min-width` and `max-width` together to create a more complex responsive design. For example, you might want to change an element's behavior at two different screen sizes. Here's an example:

.example { /* styles */ } @media (min-width: 768px) and (max-width: 992px) { .example { /* styles */ } }

In this case, the styles inside the media query will only be applied when the screen's width is greater than or equal to 768px and less than or equal to 992px.

In conclusion, understanding and effectively using `min-width` and `max-width` in Bootstrap's media queries is crucial for creating responsive and engaging web designs. By mastering these properties, you'll be well on your way to crafting dynamic and adaptable user interfaces that look great on any device. Happy coding!