Personalize the breakpoints of Bootstrap 4's grid system

In my project, I am facing a situation where I need a 1280 breakpoint to switch from desktop to tablet, instead of the xl breakpoint at 1200 as defined in Bootstrap. How can I globally change the xl breakpoint in Bootstrap without recompiling from the source files?

I attempted to modify the Sass build by setting the breakpoints like this:

$grid-breakpoints: (
  // Extra small screen / phone
  xs: 0,
  // Small screen / phone
  sm: 576px,
  // Medium screen / tablet
  md: 768px,
  // Large screen / desktop
  lg: 992px,
  // Extra large screen / wide desktop
  xl: 1280px
);

$container-max-widths: (
  sm: 540px,
  md: 720px,
  lg: 960px,
  xl: 1220px
);

Unfortunately, the xl breakpoint remained unchanged globally and still triggered at 1200px width.

Answer №1

Customizing Bootstrap 4.x & 5.x

To customize Bootstrap according to your needs, make sure to modify the $grid-breakpoints and $container-max-widths variables before you import the Bootstrap sources. Below is a sample code snippet in scss:

// File: theme.scss
// Override default BT variables:
$grid-breakpoints: (
        xs: 0,
        sm: 576px,
        md: 768px,
        lg: 992px,
        xl: 1200px,
        xxl: 1900px
);
    
$container-max-widths: (
        sm: 540px,
        md: 720px,
        lg: 960px,
        xl: 1140px,
        xxl: 1610px
);
    
// Import BT sources
@import "../node_modules/bootstrap/scss/bootstrap";

// Your CSS (SASS) rules here...

Answer №2

To make changes to the $grid-breakpoints variable, simply update it as needed. Don't forget to include /bootstrap or bootstrap/variables in your custom.scss, and then import bootstrap after.

Here's an example:

$grid-breakpoints: (
  xs: 0,
  sm: 600px,
  md: 800px,
  lg: 1000px,
  xl: 1280px
);

Check out the demo here.

For more information, refer to How to customize Bootstrap 4 with SASS

Answer №3

As outlined in their official documentation, customizing Bootstrap requires the following steps:

  1. Manually transfer desired code snippets from /scss/_variables.scss to _custom.scss
  2. Eliminate any instances of !default in the transferred code and adjust values accordingly
  3. Recompile the codebase by executing npm run dist to apply modifications (refer to the Build tools section for further instructions)

It is advised against directly altering the contents of _variables.scss, as updates to Bootstrap may overwrite such modifications. By following the aforementioned procedure, users can safely update Bootstrap while retaining their custom changes.

Note: Even if disregarding future updates, individuals who opt to edit /scss/_variables.scss directly must still recompile to propagate alterations to the /dist/ files.


In response to basZero's skepticism regarding the viability of this method, it is crucial to acknowledge Bootstrap's inherent modularity and configurability. Extensive guidance is provided through:

The meticulous detailing of the recompilation process signifies its endorsement within Bootstrap's development framework.

Additionally, tools like bootstrap.build offer online recompilation capabilities, further streamlining the customization process. By recompiling, adjustments can be made to column configurations, spacing values, responsiveness breakpoints, and module selection, allowing for tailored Bootstrap implementations.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for aligning my icon in the middle when I collapse my sidebar

Seeking assistance on centering the hamburger icon on my sidebar. Currently, when I adjust the width of the sidebar, the icon is not centered at all. Does anyone have a solution for achieving this? I attempted using justify-content: center in the main clas ...

Effortlessly move events to a different calendar using the tab menu feature in FullCalendar

My issue involves having multiple calendars within a tab container that can be switched using a navigation menu. I want to be able to drag events between these calendars using the navigation menu, but I encounter an error where if I switch tabs while dragg ...

Implementing dynamic element selection with jQuery: combining onClick and onChange events

I am looking to update the appearance of the arrow on a select option. By default, it is styled as caret-down. When a user clicks in the input area, I want to change the style to caret-up. If the select option has been changed or no action has been taken, ...

Arranging Columns in Bootstrap 4.0

I am attempting to create a layout using Bootstrap 4 that consists of two larger columns on the left and four smaller columns grouped together on the right, with the height of the four columns not exceeding the height of the two larger columns. However, I ...

How can I restrict the Bootstrap dropdown menu to only open downwards?

I'm encountering a minor issue with my Bootstrap Select Box on the following Website As you scroll up and down the page, you'll notice that the dropdown opens in both directions, which is causing disruption. I'm not sure if this is a bug ...

"Hiding elements with display: none still occupies space on the

For some reason, my Pagination nav is set to display:none but causing an empty space where it shouldn't be. Even after trying overflow:hidden, visibility:none, height:0, the issue persists. I suspect it might have something to do with relative and ab ...

In the Bootstrap multiselect feature, users will be able to choose whether to display an image or selected text

Is there any way to display an image by default instead of options? Code: <select id="example-post" style="width:120px;!important;" class="footerSelect" name="multiselect[]" multiple="multiple"> <opti ...

Troublesome Display of Badges in Bootstrap 5

My goal is to include a badge on a label, however all it does is change the text color to white <asp:Label CssClass="badge badge-pill badge-success" ID="Label1" runat="server" Text="Label"></asp:Label> ...

What is the best way to shift <p> slightly to the left using css?

I've created an HTML file structured like this. <html> <head> </head> <body> <div class="final_time"> <p class="final_time_text">some text here</p> </div> </b ...

How can I align text vertically inside a button using HTML and CSS to ensure it is at the top?

Looking for a solution to a design issue I'm facing. You can view the situation here: jsfiddle <button type="submit"> <div class="icon"></div> </button> button { width: 250px; height: 250px; background: orange ...

Customize the yellow background color of Safari's autofill feature by following these simple

When I open this image in Safari, this is what I see: https://i.stack.imgur.com/KbyGP.png However, this is the code I have: https://i.stack.imgur.com/4wEf0.png References: How to Remove WebKit's Banana-Yellow Autofill Background Remove forced ye ...

Leveraging the select class in Flask

In my Python application, I am trying to extract the selected value from an HTML/JavaScript form. Below is the snippet of my HTML code: {% block content %} <form method="post"> <div class="form-group"> <label f ...

When using Owl Carousel in Chrome, the carousel unexpectedly stops after switching tabs

Hi there, I'm currently testing out the auto play feature in owl carousel. One issue I've encountered is that when I switch to another tab in Chrome and then return to my webpage with the carousel, it stops functioning unless I manually drag the ...

Exploring the world of child theme customization in WordPress

I am looking to make some modifications to my website. Working with a child theme, I have plans to adjust the CSS and make some structural changes. Modifying the CSS seems pretty straightforward as I just need to reference the classes or IDs and input new ...

Webpack 5 now supports the mini-css-extract-plugin for efficiently extracting scss files

I am currently in the process of transitioning a webpack configuration from version 4 to include the mini-css-extract-plugin. However, I have encountered an issue where none of my first-party application CSS (SCSS) is being injected into the main app.css f ...

Tips for adjusting the color of a pin without altering anything else

I have a Google Marker with a default design. By default, I can create the pin with letters inside it. However, I want to change the color of this pin. So, I attempted to use this icon: https://i.sstatic.net/gFXMR.png Unfortunately, the letters shifted ...

Can you identify the animation being used on this button - is it CSS or JavaScript?

While browsing ThemeForest, I stumbled upon this theme: What caught my eye were the animation effects on the two buttons in the slider ("buy intense now" and "start a journey"). I tried to inspect the code using Firebug but couldn't figure it out com ...

The CSS file I've linked to in my HTML (ejs) document seems to be getting

As I work on developing my app from the backend, I am encountering an issue with loading CSS locally on my page. I am utilizing Node.js, Express.js, and EJS for my pages - part of the MEN/MEAN stack. <link href="../public/stylesheets/style.css" rel="st ...

Modifying the background image of the <body> element in CSS to reflect the season based on the current month in the calendar

I'm struggling to change my HTML background based on the date. The code I've tried isn't working as expected and I can't seem to find any relevant examples to guide me. My goal is simple - I want the background of my HTML page to be ch ...

Instructions for creating a background within a container and positioning text in the center of the image utilizing HTML and CSS

I am currently learning HTML, CSS, and JavaScript. I am in the process of building my very first website, but I have encountered a problem. I am struggling to change the background color within the container beneath the images to a specific color (#82b5cf) ...