Open In App

Bootstrap 5 Breakpoints Between Breakpoints

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.

Syntax :



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

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




@import "../node_modules/bootstrap/scss/bootstrap.scss";
.gfg{
    @include media-breakpoint-between(md, xl) {
        color: blue;
    }
}




@media (min-width: 768px) and (max-width: 1199.98px) {
    .gfg {
        color: blue;
    }
}




<!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=
          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.




@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;
    }
}




@media (min-width: 768px) and (max-width: 1199.98px) {
    .gfg {
        color: blue;
    }
}
@media (min-width: 576px) and (max-width: 1199.98px) {
    .header {
        color: red;
    }
}




<!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=
          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


Article Tags :