How to customize Bootstrap's breakpoints
To customize the breakpoints of Bootstrap, it is recommended to use the Sass method. First, redefine the $grid-breakpoints and $container-max-widths variables before importing Bootstrap to match design requirements. 1. Modify the existing breakpoint value (such as changing md from 768px to 800px), 2. You can add new breakpoints (such as xxl or huge) or rename existing breakpoints, 3. Synchronize the maximum width of the container to ensure the consistent layout, 4. Use media query mixing (such as @include media-breakpoint-up(md)) to apply the responsive style, 5. Recompile Sass to generate custom CSS; if Sass cannot be used, you can try CSS coverage, but it is not recommended, because it is difficult to maintain and easily conflict-free, and you should always achieve flexible and sustainable breakpoint customization through Sass construction.

Customizing Bootstrap's breakpoints is useful when you want to align your responsive design with specific device sizes or design requirements that different from Bootstrap's defaults. Whether you're using Bootstrap with Sass (recommended) or overriding CSS, here's how to do it properly.

Modify Breakpoints Using Sass (Recommended)
If you're using Bootstrap via Sass (eg, in a project with npm, Webpack, or similar), you can customize breakpoints at compile time by overriding the Sass variables before importing Bootstrap.
-
Set up Bootstrap with Sass
Make sure you're importing Bootstrap in a Sass file (eg,styles.scss) rather than linking to the precompiled CSS.
-
Override the
$grid-breakpointsand$container-max-widthsvariables
Bootstrap uses two main variables:-
$grid-breakpoints: Defines the minimum width for each breakpoint (eg,sm,md). -
$container-max-widths: Sets the max width of.containerat each breakpoint.
Example: Change
mdfrom 768px to 800px and add a customxlbreakpoint.
// Custom breakpoints $grid-breakpoints: ( xs: 0, sm: 576px, md: 800px, // Changed from 768px lg: 1000px, // Changed from 992px xl: 1400px, // Changed from 1200px xxl: 1600px // Optional: add a new breakpoint ); // Update container widths to match $container-max-widths: ( sm: 540px, md: 760px, lg: 960px, xl: 1360px, xxl: 1560px ); // Now import Bootstrap @import "bootstrap/scss/bootstrap";
⚠️ Important: Define your custom variables before importing Bootstrap. Otherwise, the defaults will be used.
-
Use your custom breakpoints in media queries
You can now use Bootstrap's responsive utilities or Sass mixins with your new values..custom-element { @include media-breakpoint-up(md) { font-size: 20px; } }This will now trigger at 800px instead of 768px.
Add or Rename Breakpoints
You can also add new breakpoints or rename existing ones.
$grid-breakpoints: ( xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px, xxl: 1400px, // New breakpoint huge: 1800px // Fully custom name ); $container-max-widths: ( ..., xxl: 1360px, huge: 1760px );
Now you can use @include media-breakpoint-up(huge) in your styles.
Recompile Bootstrap
After making changes, recompile your Sass to generate the updated CSS. If you're using a build tool like Webpack, Vite, or a task runner, this happens automatically when you save.
Override with CSS (Not Recommended)
If you can't use Sass, you can override responsive utility classes with custom CSS, but this is limited and not scalable.
Example: Force .col-md-* to behave differently.
/* Override md behavior — fragile and not recommended */
@media (min-width: 800px) {
.custom-col-md-6 {
flex: 0 0 50%;
max-width: 50%;
}
}This approach doesn't scale well and can conflict with Bootstrap's built-in classes.
Key Tips
- Always adjust both
$grid-breakpointsand$container-max-widthsto keep layout consistency. - Use
@include media-breakpoint-up(),-down(), and-only()for clean, readable responsive code. - Avoid using pixel values directly in your media queries—use Bootstrap's mixins to stay consistent.
- If adding a new breakpoint, update the grid system by recompiling and ensure utilities like
d-xl-nonework as expected.
Basically, customizing breakpoints is straightforward if you control the Sass build. Just redefine the variables before import and recompile. It's flexible and maintainable—way better than hacking CSS after the fact.
The above is the detailed content of How to customize Bootstrap's breakpoints. For more information, please follow other related articles on the PHP Chinese website!
Hot AI Tools
Undress AI Tool
Undress images for free
AI Clothes Remover
Online AI tool for removing clothes from photos.
Undresser.AI Undress
AI-powered app for creating realistic nude photos
ArtGPT
AI image generator for creative art from text prompts.
Stock Market GPT
AI powered investment research for smarter decisions
Hot Article
Popular tool
Notepad++7.3.1
Easy-to-use and free code editor
SublimeText3 Chinese version
Chinese version, very easy to use
Zend Studio 13.0.1
Powerful PHP integrated development environment
Dreamweaver CS6
Visual web development tools
SublimeText3 Mac version
God-level code editing software (SublimeText3)
Hot Topics
20519
7
13632
4
How to animate Bootstrap components for a more dynamic feel? (Advanced CSS)
Mar 13, 2026 am 01:13 AM
The fade and show classes of Bootstrap5 are only status markers and do not contain animation logic. You need to manually add @keyframes or transitions to achieve fade-in and fade-out; custom components need to configure additional animation rules, and when JS controls the display, the show class must be added with delay to ensure redrawing.
How to ensure your Bootstrap site is fully accessible (WCAG)? (Accessibility)
Mar 08, 2026 am 01:25 AM
The Bootstrap component does not automatically add the aria attributes required for complete WCAG. You need to manually complete aria-expanded, role="dialog", aria-labelledby, etc.; the form must be equipped with an explicit label; :focus needs to use :focus-visible to ensure that the keyboard focus is visible; the color contrast must reach 4.5:1.
How to create a professional-looking landing page with Bootstrap? (Project-Based)
Mar 10, 2026 am 12:22 AM
Bootstrap’sdefaultstylingfeelsgenericduetouncustomizedspacing,typography,andcolor—fixableviaCSSvariablesorSass,notdirectedits;avoidfixedwidths,misuseofgridclasses,andrender-blockingassetstoensureresponsivenessandfastLCP.
How to integrate Bootstrap with a JavaScript framework like React or Vue? (Integration)
Mar 12, 2026 am 01:22 AM
Only BootstrapCSS should be introduced in React/Vue instead of JS to avoid global style pollution and jQuery dependency; SCSS modules should be imported on demand to reduce the size; interactive functions must be imported with encapsulation libraries (such as react-bootstrap) or ESM; grid classes need to adapt to JSX/Vue syntax, and explicit and implicit classes should be used with SSR with caution.
How to implement a carousel or image slider with Bootstrap? (Content Display)
Mar 07, 2026 am 01:01 AM
Need not. Bootstrap5's carousel is automatically initialized by default. You need to manually call newbootstrap.Carousel() only when data-bs-ride is modified or the element is dynamically inserted.
How to properly install and set up Bootstrap 5 in your web project? (Getting Started)
Mar 16, 2026 am 12:40 AM
To correctly introduce Bootstrap5, you need to load bootstrap.min.css first, then load bootstrap.bundle.min.js (including Popper), and ensure that the viewport tag exists; after npm installation, you need to manually introduce compiled files in the dist directory. SCSS customization must be preceded by variable declarations, and JS components must be explicitly initialized to avoid jQuery contamination.
How to use Bootstrap utility classes to speed up your workflow? (Efficiency)
Mar 11, 2026 am 12:18 AM
Use mt-3 to represent the top margin, mb-3 to represent the bottom margin, and the suffixes t/b/s/e correspond to top/bottom/start/end respectively; ms-auto implements right alignment in the flex container, me-2 replaces the abandoned mr-2, and responsive classes such as mt-md-4 need to have breakpoint prefixes.
How to use Bootstrap variables to maintain a consistent color scheme? (Branding)
Mar 14, 2026 am 12:59 AM
The safest way is to redefine Bootstrap's Sass variables (such as $primary, $primary-rgb, $primary-text-emphasis) in advance and introduce them before @import "bootstrap/scss/variables" to ensure that all dependent variables are updated synchronously to avoid compilation failure or style exceptions.






