Bootstrap Components

Bootstrap Media queries

Overview

As we talked before in the modern internet which gets browsed almost equally by mobile and desktop devices having your pages adjusting responsively to the screen they get displayed on is a must. That's why we have the powerful Bootstrap framework at our side in its latest fourth version – still in development up to alpha 6 released at this point.

But what is this thing under the hood which it actually uses to do the job – how the page's content gets reordered accordingly and what makes the columns caring the grid tier infixes like -sm- -md- and so on display inline down to a specific breakpoint and stack over below it? How the grid tiers actually work? This is what we're going to take a look at in this one.

Efficient ways to employ the Bootstrap media queries:

The responsive behavior of the most popular responsive framework in its latest fourth version gets to work thanks to the so called media queries. What they do is taking count of the width of the viewport – the screen of the device or the width of the browser window if the page gets displayed on desktop and applying different styling rules accordingly. So in common words they follow the simple logic – is the width above or below a certain value – and respectfully trigger on or off.

Each viewport size – like Small, Medium and so on has its own media query defined except for the Extra Small screen size which in the latest alpha 6 release has been applied universally and the -xs- infix – dropped so now instead of writing .col-xs-6 we just need to type .col-6 and get an element spreading half of the screen at any width.

The general syntax

The general syntax of the media queries in the Bootstrap framework is @media (min-width: ~ breakpoint in pixels here ~) ~ some CSS rules to be applied ~ which narrows the CSS rules defined down to a specific viewport size but eventually the opposite query might be used like @media (max-width: ~ breakpoint in pixels here ~) ~ some CSS ~ which will apply up to reaching the specified breakpoint width and no further.

Another detail to bear in mind

Interesting thing to notice here is that the breakpoint values for the different screen sizes differ by a single pixel depending to the rule which has been used like:

Small screen sizes - ( min-width: 576px) and ( max-width: 575px),

Medium screen size - ( min-width: 768px) and ( max-width: 767px),

Large screen size - ( min-width: 992px) and ( max-width: 591px),

And Extra large screen sizes - ( min-width: 1200px) and ( max-width: 1199px),

Responsive media queries breakpoints

Due to the fact that Bootstrap is undoubtedly produced to become mobile first, we apply a small number of media queries to develop sensible breakpoints for user interfaces and layouts . These kinds of breakpoints are normally accordinged to minimal viewport widths as well as enable us to graduate up components when the viewport changes.

Bootstrap mainly makes use of the following media query ranges - or breakpoints - in source Sass documents for design, grid program, and elements.

// Extra small devices (portrait phones, less than 576px)
// No media query since this is the default in Bootstrap

// Small devices (landscape phones, 576px and up)
@media (min-width: 576px)  ... 

// Medium devices (tablets, 768px and up)
@media (min-width: 768px)  ... 

// Large devices (desktops, 992px and up)
@media (min-width: 992px)  ... 

// Extra large devices (large desktops, 1200px and up)
@media (min-width: 1200px)  ...

Since we formulate source CSS in Sass, every media queries are really provided through Sass mixins:

@include media-breakpoint-up(xs)  ... 
@include media-breakpoint-up(sm)  ... 
@include media-breakpoint-up(md)  ... 
@include media-breakpoint-up(lg)  ... 
@include media-breakpoint-up(xl)  ... 

// Example usage:
@include media-breakpoint-up(sm) 
  .some-class 
    display: block;

We periodically utilize media queries which work in the other direction (the given display dimension or smaller):

// Extra small devices (portrait phones, less than 576px)
@media (max-width: 575px)  ... 

// Small devices (landscape phones, less than 768px)
@media (max-width: 767px)  ... 

// Medium devices (tablets, less than 992px)
@media (max-width: 991px)  ... 

// Large devices (desktops, less than 1200px)
@media (max-width: 1199px)  ... 

// Extra large devices (large desktops)
// No media query since the extra-large breakpoint has no upper bound on its width

Again, such media queries are additionally attainable by means of Sass mixins:

@include media-breakpoint-down(xs)  ... 
@include media-breakpoint-down(sm)  ... 
@include media-breakpoint-down(md)  ... 
@include media-breakpoint-down(lg)  ...

There are also media queries and mixins for targeting a single sector of screen dimensions employing the lowest and highest breakpoint widths.

// Extra small devices (portrait phones, less than 576px)
@media (max-width: 575px)  ... 

// Small devices (landscape phones, 576px and up)
@media (min-width: 576px) and (max-width: 767px)  ... 

// Medium devices (tablets, 768px and up)
@media (min-width: 768px) and (max-width: 991px)  ... 

// Large devices (desktops, 992px and up)
@media (min-width: 992px) and (max-width: 1199px)  ... 

// Extra large devices (large desktops, 1200px and up)
@media (min-width: 1200px)  ...

Such media queries are additionally readily available with Sass mixins:

@include media-breakpoint-only(xs)  ... 
@include media-breakpoint-only(sm)  ... 
@include media-breakpoint-only(md)  ... 
@include media-breakpoint-only(lg)  ... 
@include media-breakpoint-only(xl)  ...

Additionally, media queries may well cover numerous breakpoint sizes:

// Example
// Apply styles starting from medium devices and up to extra large devices
@media (min-width: 768px) and (max-width: 1199px)  ... 
<code/>

The Sass mixin for aim at the similar screen dimension variety would be:

<code>
@include media-breakpoint-between(md, xl)  ...

Final thoughts

Do note once more – there is no -xs- infix and a @media query for the Extra small – less then 576px screen size – the rules for this one get universally applied and do trigger after the viewport gets narrower than this value and the wider viewport media queries go off.

This improvement is aiming to lighten up both the Bootstrap 4's style sheets and us as developers since it follows the natural logic of the way responsive content works stacking up after a certain point and with the dropping of the infix there will be less writing for us.

Take a look at a number of video clip tutorials regarding Bootstrap media queries:

Linked topics:

Media queries main information

Media queries {official| main| formal| approved| authoritative} {documentation| documents| information| records}

Bootstrap 4: Responsive media queries breakpoints

Bootstrap 4: Responsive media queries breakpoints

Bootstrap 4 - Media Queries Method

Bootstrap 4 - Media Queries Method

Best Free AI Website Builder

Generate AI websites with a simple prompt! Type in any language, export in zip.


AI Website Builder



Best Free Website Builder Software

Create awesome websites offline! No coding. 9900+ templates. Edit and save locally, upload wherever.


Free website builder download for Win, Mac, Linux!



Best Website Templates

HTML Business Templates

HTML Business Templates

Web Design HTML Templates

Web Design HTML Templates

HTML eCommerce Website Template

HTML eCommerce Website Template

Hotel HTML Template

Hotel HTML Template

Landing Page HTML Template

Landing Page HTML Template

Premium Design HTML Themes

Premium Design HTML Themes

HTML Resume Template

HTML Resume Template

Online Shopping HTML Template

Online Shopping HTML Template

HTML Responsive Templates

HTML Responsive Templates

Latest Posts

  1. AI website creator and generator - how to create a website with AI in just 2 minutes.
  2. Best Free AI website generator and builder - create a website design with AI.
  3. Best Website Builder AIBest Free AI Website Builder - Create Website Design with AI
  4. Best Website Builder for Consultants, Magazines, Churches, Authors
  5. Best Website Builder for Designers, Videos, Education, Software Companies
  6. Website Builder for Beginners, Bloggers, Writers, IT Companies
  7. Best Website Builder for Restaurants, Online Stores, Real Estate, Musicians
  8. Best Website Builder for podcasts and affiliate marketing
  9. Therapists and nonprofits Website Builder
  10. Portfolio and SEO Website Builder
  11. Website Builder for Kids and Musicians
  12. Website Builder for Photographers and Artists
  13. HTML Code Generator - HTML Code Creator
  14. Web Design Program - Website Design Tool
  15. Landing Page Generator - Landing Page Builder
  16. No Coding Website Builder - Website Builder For Small Business
  17. Innovative HTML Builder Drag And Drop Free for Your Next Project
  18. Is There A Completely Free QR Code Generator
  19. Extremely Comfortable Business Website Constructor Review
  20. Bootstrap Select
  21. Bootstrap Panel
  22. Bootstrap Tabs
  23. Bootstrap Toggle
  24. Bootstrap Modal Popup
  25. Bootstrap Row
  26. Bootstrap Multiselect
  27. Bootstrap Login Forms
  28. Bootstrap Layout
  29. Bootstrap Jumbotron
  30. Bootstrap Button Group
  31. Bootstrap Breakpoints
  32. Bootstrap Navbar
  33. Bootstrap Tooltip
  34. Bootstrap Textarea
  35. Bootstrap Switch
  36. Bootstrap Slider
  37. Bootstrap Progress Bar
  38. Bootstrap Label
  39. Bootstrap Header
  40. Bootstrap Clearfix
  41. Bootstrap Sidebar
  42. Bootstrap Radio
  43. Bootstrap Offset
  44. Bootstrap Menu
  45. Bootstrap Columns
  46. Bootstrap Checkbox
  47. Bootstrap Accordion
  48. Bootstrap Image
  49. Bootstrap Grid
  50. Bootstrap Form
  51. Bootstrap Glyphicons
  52. Bootstrap List
  53. Bootstrap Carousel
  54. Bootstrap Icons
  55. Bootstrap Collapse
  56. Bootstrap Popover
  57. Bootstrap Input
  58. Bootstrap Modal
  59. Bootstrap Pagination
  60. Bootstrap Button
  61. Bootstrap Alert
  62. Bootstrap Table