Bird
Raised Fist0
Bootsrapmarkup~5 mins

Custom breakpoints in Bootsrap

Choose your learning style10 modes available
Introduction

Custom breakpoints let you control when your website layout changes on different screen sizes. This helps your site look good on all devices.

You want your site to look different on a tablet than on a phone or desktop.
You need a special layout for a screen size not covered by default breakpoints.
You want to improve readability by adjusting font sizes at specific widths.
You want to hide or show elements only on certain screen widths.
You want to create a unique design that fits your brand's style on all devices.
Syntax
Bootsrap
// In your SCSS file
$grid-breakpoints: (
  xs: 0,
  sm: 480px,
  md: 768px,
  lg: 1024px,
  xl: 1280px,
  xxl: 1440px
);

@import 'bootstrap';

Custom breakpoints are set in SCSS before importing Bootstrap.

Each breakpoint has a name and a minimum width value.

Examples
This example uses Bootstrap's default breakpoints.
Bootsrap
$grid-breakpoints: (
  sm: 576px,
  md: 768px,
  lg: 992px,
  xl: 1200px
);

@import 'bootstrap';
This example creates custom names and sizes for breakpoints.
Bootsrap
$grid-breakpoints: (
  mobile: 0,
  tablet: 640px,
  desktop: 1024px
);

@import 'bootstrap';
This example adjusts breakpoints to fit a specific design need.
Bootsrap
$grid-breakpoints: (
  sm: 500px,
  md: 800px,
  lg: 1100px,
  xl: 1400px
);

@import 'bootstrap';
Sample Program

This example shows a box that changes color at custom screen widths: 480px, 768px, and 1024px. It uses CSS media queries to simulate custom breakpoints.

Bootsrap
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <title>Bootstrap Custom Breakpoints Example</title>
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" />
  <style>
    /* Custom breakpoints example using media queries */
    @media (min-width: 480px) {
      .custom-box {
        background-color: lightblue;
      }
    }
    @media (min-width: 768px) {
      .custom-box {
        background-color: lightgreen;
      }
    }
    @media (min-width: 1024px) {
      .custom-box {
        background-color: lightcoral;
      }
    }
  </style>
</head>
<body>
  <main class="container py-5">
    <h1 class="mb-4">Custom Breakpoints Demo</h1>
    <div class="custom-box p-5 text-center">
      Resize the browser window to see the background color change.
    </div>
  </main>
</body>
</html>
OutputSuccess
Important Notes

Bootstrap's default breakpoints are sm, md, lg, xl, and xxl.

To use custom breakpoints, you must customize Bootstrap's SCSS and recompile it.

For quick testing, CSS media queries can simulate custom breakpoints without rebuilding Bootstrap.

Summary

Custom breakpoints help your site adapt to different screen sizes beyond defaults.

Set breakpoints in SCSS before importing Bootstrap to change them.

Use media queries to test or add styles for your custom breakpoints.

Practice

(1/5)
1. What is the main purpose of custom breakpoints in Bootstrap?
easy
A. To disable responsive design completely
B. To change the colors of Bootstrap components
C. To add new fonts to the Bootstrap theme
D. To define new screen widths where the layout changes

Solution

  1. Step 1: Understand what breakpoints do

    Breakpoints tell Bootstrap when to change layout based on screen size.
  2. Step 2: Identify the role of custom breakpoints

    Custom breakpoints let you add or change these screen widths to better fit your design.
  3. Final Answer:

    To define new screen widths where the layout changes -> Option D
  4. Quick Check:

    Custom breakpoints = new layout widths [OK]
Hint: Breakpoints control layout changes by screen size [OK]
Common Mistakes:
  • Thinking breakpoints change colors or fonts
  • Confusing breakpoints with disabling responsiveness
  • Assuming breakpoints only affect mobile views
2. Which SCSS variable would you modify to add a new custom breakpoint in Bootstrap?
easy
A. $grid-breakpoints
B. $colors
C. $font-family-base
D. $container-max-widths

Solution

  1. Step 1: Identify SCSS variables related to breakpoints

    Bootstrap uses $grid-breakpoints to define screen widths for breakpoints.
  2. Step 2: Confirm which variable controls breakpoints

    Modifying $grid-breakpoints lets you add or change custom breakpoints.
  3. Final Answer:

    $grid-breakpoints -> Option A
  4. Quick Check:

    Breakpoint variable = $grid-breakpoints [OK]
Hint: Breakpoints are set in $grid-breakpoints SCSS variable [OK]
Common Mistakes:
  • Changing $colors instead of breakpoints
  • Modifying font or container width variables
  • Trying to add breakpoints in CSS instead of SCSS
3. Given this SCSS snippet, what is the minimum screen width for the custom breakpoint xxl?
$grid-breakpoints: (
  xs: 0,
  sm: 576px,
  md: 768px,
  lg: 992px,
  xl: 1200px,
  xxl: 1400px
);
medium
A. 1200px
B. 1400px
C. 992px
D. 768px

Solution

  1. Step 1: Locate the xxl key in the map

    The map shows xxl: 1400px, meaning the breakpoint starts at 1400 pixels.
  2. Step 2: Understand breakpoint meaning

    Bootstrap applies styles for xxl at screen widths 1400px and above.
  3. Final Answer:

    1400px -> Option B
  4. Quick Check:

    xxl breakpoint = 1400px [OK]
Hint: Check the value next to the breakpoint name [OK]
Common Mistakes:
  • Confusing breakpoint names with values
  • Picking the previous breakpoint's width
  • Ignoring the unit (px) in values
4. You added a custom breakpoint xxl at 1400px but your styles for it are not applying. What is the most likely mistake?
medium
A. You forgot to import Bootstrap SCSS after setting the breakpoint
B. You defined xxl inside $colors variable
C. You used @media (min-width: 1400) without units
D. You wrote CSS inside body instead of html

Solution

  1. Step 1: Check common syntax errors in media queries

    Media queries require units like px for widths, missing units cause failure.
  2. Step 2: Identify the error in the options

    You used @media (min-width: 1400) without units shows @media (min-width: 1400) missing px, so styles won't apply.
  3. Final Answer:

    You used @media (min-width: 1400) without units -> Option C
  4. Quick Check:

    Media query units required [OK]
Hint: Always include units like px in media queries [OK]
Common Mistakes:
  • Forgetting units in media queries
  • Not importing Bootstrap SCSS after changes
  • Defining breakpoints in wrong variables
  • Confusing CSS selectors with media queries
5. You want to add a custom breakpoint at 1600px named xxxl. Which SCSS code correctly adds it and sets container max width for it?
hard
A. $grid-breakpoints: map-merge($grid-breakpoints, (xxxl: 1600px)); $container-max-widths: map-merge($container-max-widths, (xxxl: 1540px));
B. $grid-breakpoints: (xxxl: 1600px); $container-max-widths: (xxxl: 1540px);
C. $grid-breakpoints: map-merge($colors, (xxxl: 1600px)); $container-max-widths: map-merge($container-max-widths, (xxxl: 1540px));
D. $grid-breakpoints: map-merge($grid-breakpoints, (xxxl: 1600)); $container-max-widths: map-merge($container-max-widths, (xxxl: 1540));

Solution

  1. Step 1: Add new breakpoint using map-merge

    Use map-merge to add xxxl: 1600px to existing $grid-breakpoints.
  2. Step 2: Set container max width for new breakpoint

    Similarly, add xxxl: 1540px to $container-max-widths using map-merge.
  3. Step 3: Check for correct syntax and units

    $grid-breakpoints: map-merge($grid-breakpoints, (xxxl: 1600px)); $container-max-widths: map-merge($container-max-widths, (xxxl: 1540px)); uses correct variables, map-merge, and includes units px.
  4. Final Answer:

    Correctly merges new breakpoint and container width with units -> Option A
  5. Quick Check:

    Use map-merge with units for custom breakpoints [OK]
Hint: Use map-merge with px units to add breakpoints [OK]
Common Mistakes:
  • Overwriting variables instead of merging
  • Missing px units in values
  • Merging into wrong variables like $colors
  • Using incomplete or invalid SCSS syntax
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard