Open In App

Bootstrap 5 Breakpoints Between Breakpoints

Last Updated : 29 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

We use media queries to create sensible breakpoints for our interfaces and layouts. There are media queries and mixins for targeting multiple segments of screen sizes using the minimum and maximum breakpoint widths. We use xs, md, lg, xl, xxl for various viewport sizes.

  • @include media-breakpoint-between(md, xl) { ... }  - Apply styles starting from medium devices and up to extra large devices.

Syntax :

@include media-breakpoint-between(md, xl) { ... }

Example 1: Using between breakpoints from viewport size md to xl.

SCSS
@import "../node_modules/bootstrap/scss/bootstrap.scss";
.gfg{
    @include media-breakpoint-between(md, xl) {
        color: blue;
    }
}
CSS
@media (min-width: 768px) and (max-width: 1199.98px) {
    .gfg {
        color: blue;
    }
}
HTML
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link href=
"https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" 
          rel="stylesheet">
    <style>
        @media (min-width: 768px) and (max-width: 1199.98px){
            .gfg {
                color: blue;
            }
        }
    </style>
</head>

<body>
    <div class="text-center">
        <h1 class="text-success">
            GeeksforGeeks
        </h1>
        <h2>
            Bootstrap5 Breakpoints Between breakpoints
        </h2>
        <br>
        <div class="gfg">
            <h6>
                This text will change to blue color 
                between md and xl breakpoints
            </h6>
        </div>
    </div>
</body>
</html>

Output:

Example 2: Using between breakpoints on two different HTML components for different viewport sizes.

SCSS
@import "../node_modules/bootstrap/scss/bootstrap.scss";
.gfg {
    @include media-breakpoint-between(md, xl) {
        color: blue;
    }
}
.header {
    @include media-breakpoint-between(sm, xl) {
        color: red;
    }
}
CSS
@media (min-width: 768px) and (max-width: 1199.98px) {
    .gfg {
        color: blue;
    }
}
@media (min-width: 576px) and (max-width: 1199.98px) {
    .header {
        color: red;
    }
}
HTML
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link href=
"https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" 
          rel="stylesheet">
  <style>
    @media (min-width: 768px) and (max-width: 1199.98px){
         .gfg {
               color: blue;
         }
    }
    @media (min-width: 576px) and (max-width: 1199.98px){
         .header {
               color: red;
         }
    }
  </style>
</head>

<body>
    <div class="text-center">
        <h1 class="text-success">
            GeeksforGeeks
        </h1>
        <h2>
            Bootstrap5 Breakpoints Between breakpoints
        </h2>
        <br>
        <div class="gfg">
            <p>
                This text will change to blue color 
                between md and xl breakpoints
            </p>
            <p class="header">
                This text will change to red color 
                between sm and xl breakpoints
            </p>
        </div>
    </div>
</body>
</html>

Output:

References: https://getbootstrap.com/docs/5.0/layout/breakpoints/#between-breakpoints


Next Article

Similar Reads