Custom breakpoints let you control when your website layout changes on different screen sizes. This helps your site look good on all devices.
Custom breakpoints in 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.
$grid-breakpoints: ( sm: 576px, md: 768px, lg: 992px, xl: 1200px ); @import 'bootstrap';
$grid-breakpoints: ( mobile: 0, tablet: 640px, desktop: 1024px ); @import 'bootstrap';
$grid-breakpoints: ( sm: 500px, md: 800px, lg: 1100px, xl: 1400px ); @import 'bootstrap';
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.
<!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>
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.
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
custom breakpoints in Bootstrap?Solution
Step 1: Understand what breakpoints do
Breakpoints tell Bootstrap when to change layout based on screen size.Step 2: Identify the role of custom breakpoints
Custom breakpoints let you add or change these screen widths to better fit your design.Final Answer:
To define new screen widths where the layout changes -> Option DQuick Check:
Custom breakpoints = new layout widths [OK]
- Thinking breakpoints change colors or fonts
- Confusing breakpoints with disabling responsiveness
- Assuming breakpoints only affect mobile views
Solution
Step 1: Identify SCSS variables related to breakpoints
Bootstrap uses$grid-breakpointsto define screen widths for breakpoints.Step 2: Confirm which variable controls breakpoints
Modifying$grid-breakpointslets you add or change custom breakpoints.Final Answer:
$grid-breakpoints -> Option AQuick Check:
Breakpoint variable = $grid-breakpoints [OK]
- Changing $colors instead of breakpoints
- Modifying font or container width variables
- Trying to add breakpoints in CSS instead of SCSS
xxl?
$grid-breakpoints: ( xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px, xxl: 1400px );
Solution
Step 1: Locate the
The map showsxxlkey in the mapxxl: 1400px, meaning the breakpoint starts at 1400 pixels.Step 2: Understand breakpoint meaning
Bootstrap applies styles forxxlat screen widths 1400px and above.Final Answer:
1400px -> Option BQuick Check:
xxl breakpoint = 1400px [OK]
- Confusing breakpoint names with values
- Picking the previous breakpoint's width
- Ignoring the unit (px) in values
xxl at 1400px but your styles for it are not applying. What is the most likely mistake?Solution
Step 1: Check common syntax errors in media queries
Media queries require units likepxfor widths, missing units cause failure.Step 2: Identify the error in the options
You used@media (min-width: 1400)without units shows@media (min-width: 1400)missingpx, so styles won't apply.Final Answer:
You used @media (min-width: 1400) without units -> Option CQuick Check:
Media query units required [OK]
- Forgetting units in media queries
- Not importing Bootstrap SCSS after changes
- Defining breakpoints in wrong variables
- Confusing CSS selectors with media queries
xxxl. Which SCSS code correctly adds it and sets container max width for it?Solution
Step 1: Add new breakpoint using map-merge
Usemap-mergeto addxxxl: 1600pxto existing$grid-breakpoints.Step 2: Set container max width for new breakpoint
Similarly, addxxxl: 1540pxto$container-max-widthsusingmap-merge.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 unitspx.Final Answer:
Correctly merges new breakpoint and container width with units -> Option AQuick Check:
Use map-merge with units for custom breakpoints [OK]
- Overwriting variables instead of merging
- Missing px units in values
- Merging into wrong variables like $colors
- Using incomplete or invalid SCSS syntax
Ready to prove it?
Pass the test and this pattern moves unknown
