Skip to content
Tutorials Center
My learning

Topics

Lesson 5 of 58 ยท Layout

Breakpoints and Responsive Design

Understand Bootstrap 5's six breakpoints, mobile-first min-width media queries and responsive class infixes, and learn to test every size in the live editor.

People open your page on phones, tablets, laptops and huge monitors. Responsive design means the same HTML adapts to each screen instead of forcing one fixed layout on everybody. Bootstrap's tool for this is the breakpoint: a screen width at which the layout is allowed to change. Almost every Bootstrap class you will learn, from columns to margins to display rules, can be tied to a breakpoint.

This lesson explains the six breakpoints, the mobile-first idea behind them, and the naming pattern (sm, md, lg...) that appears in class names throughout the framework. You should know what a container is before continuing.

The six breakpoints

Name Class infix Starts at (min-width) Typical device
Extra small (none) 0 Phones in portrait
Small sm 576px Phones in landscape
Medium md 768px Tablets
Large lg 992px Small laptops
Extra large xl 1200px Desktops
Extra extra large xxl 1400px Large monitors

These are not exact device sizes; they are convenient cut points. The extra-small tier has no infix because it is the default: a class without an infix applies from width 0 and up, so it applies everywhere.

Mobile first and min-width

Bootstrap is mobile first. You style the small screen first, and then you add rules that kick in as the screen gets larger. Technically every breakpoint is a min-width media query:

CSS
/* applies at 768px and wider */
@media (min-width: 768px) { ... }

A class with the md infix therefore means "from md and up", not "only at md". This has a very useful consequence: you only need to describe changes. Look at col-12 col-md-6. On phones the column is 12 of 12 (full width). From 768px on, it is 6 of 12 (half). You never have to say what happens at lg or xl, because the md rule keeps applying until you override it.

flowchart LR
  XS["xs<br/>0 and up"] --> SM["sm<br/>576 and up"] --> MD["md<br/>768 and up"] --> LG["lg<br/>992 and up"] --> XL["xl<br/>1200 and up"] --> XXL["xxl<br/>1400 and up"]

Each breakpoint inherits everything from the smaller ones unless a larger rule replaces it.

If you work the other way round (designing for desktop first and then fixing phones), you end up writing many overrides. Mobile-first usually gives smaller, simpler CSS and loads faster on weak devices.

Responsive class infixes

Many Bootstrap families follow the same naming recipe: -{breakpoint}-{value}. The breakpoint part is left out for extra small. A few families you will meet:

Family Examples
Columns col-6, col-md-4, col-xl-3
Display d-none, d-md-block, d-lg-flex
Text alignment text-center, text-md-start
Spacing p-2, p-lg-5, mt-md-4
Flex direction flex-column, flex-md-row
Containers container-md, container-xl
Navbar navbar-expand-lg

Learn the pattern once and you can read class lists you have never seen. For example d-none d-md-block reads: "hidden by default, block from the medium breakpoint upward".

Seeing the current breakpoint

The best way to understand breakpoints is to watch them switch. The next example uses responsive display classes: only one label shows at a time, and a few lines of JavaScript print the window width. Make the browser window wider and narrower, and the label changes at the widths in the table above.

Which breakpoint is active?

Look at one label, for example the SM one: d-none d-sm-inline d-md-none. It starts hidden, turns on at sm, and turns off again at md. Because rules for larger breakpoints win, the last matching class decides.

Testing sizes in the live editor

On this site the preview is as wide as the editor area, so you can test small screens by narrowing your browser window. Browser DevTools also have a device toolbar (usually the phone-and-tablet icon, or Ctrl+Shift+M) where you can type any width and pick device presets. Another handy trick when you want to see several widths at once is to embed your layout in <iframe> elements of fixed widths. The next demo places the same small layout in three frames: 360px (phone), 768px (tablet) and 1100px (desktop). The frames use srcdoc, so the whole demo is self-contained.

One layout at three screen widths

At 360px every box fills the row. At 768px A and B share the first row while C sits below it (col-md-12, one column wide on its own row). At 1100px the three boxes sit side by side. Each frame has its own width, so the media queries inside it react to that width and not to the page around it. This is exactly how a real device behaves, and it is a good way to check your work.

Writing media queries yourself

When Bootstrap's classes are not enough you can write your own CSS with the same breakpoints. Use min-width to stay consistent with the framework:

CSS
.sidebar { display: none; }
@media (min-width: 992px) {
  .sidebar { display: block; }
}

Stick to Bootstrap's six values (576, 768, 992, 1200, 1400) rather than inventing new ones. With Sass you can use mixins such as @include media-breakpoint-up(lg), which keeps the numbers in a single place (see Customizing with Sass).

Bootstrap also offers max-width media queries, used for rules that should only apply below a breakpoint. Their upper limits are written as the next breakpoint minus 0.02px (for example 767.98px) to avoid a gap caused by fractional pixels on high-density screens.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does the class d-md-none mean?

    Breakpoint infixes are min-width rules, so d-md-none applies at 768px and everything wider. To hide something only on small screens, use d-none d-md-block.
  2. 2. Which approach describes Bootstrap's design strategy?

    Base styles target the smallest screens, and breakpoint classes add changes as the viewport gets wider.
  3. 3. At a window width of 800px, which breakpoint is active?

    md starts at 768px and lg at 992px, so 800px falls in the md range.
  4. 4. How do you read the classes col-12 col-lg-4?

    col-12 applies from 0 upwards. col-lg-4 takes over at 992px and up, giving 4 of 12 columns.

Summary

  • Bootstrap has six breakpoints: xs (0), sm (576), md (768), lg (992), xl (1200) and xxl (1400).
  • It is mobile first: breakpoint classes are min-width rules meaning "this size and up".
  • The infix goes between the property and the value, as in col-md-6, d-lg-none, text-xl-end.
  • You only describe changes; smaller rules continue to apply until a larger one replaces them.
  • Test widths with the browser window, DevTools device mode, or fixed-width iframes.

Next: The Grid System.