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