Bootstrap Container Queries

Version 3 (Bootstrap 5) · Version 4 (Bootstrap 6)

What is it?

Bootstrap's responsive classes react to the viewport. This library adds classes that react to the width of a parent container instead, using CSS container queries. This is the 3.x line, for Bootstrap 5.

Install

npm i bootstrap-container-queries@3

With CSS, after Bootstrap 5:

<link href="bootstrap-container-queries.min.css" rel="stylesheet" />

With Sass (@use or @import):

@use "bootstrap-container-queries/scss/bootstrap-container-queries";

Usage

Add .bcq to the parent, then use the bcq- classes. They follow the Bootstrap names with the bcq- prefix, and base classes exist too (bcq-d-none).

<div class="bcq row">
  <div class="bcq-sm-6 bcq-lg-3">...</div>
</div>
<div class="bcq">
  <div class="bcq-d-none bcq-d-md-block">Visible from md</div>
</div>

Reference

Breakpoints: sm 30em, md 48em, lg 62em, xl 75em, xxl 90em (em of the container).

Feature Classes
Grid bcq-{size}, bcq-{bp}-{size}
Display bcq-d-{value}, bcq-d-{bp}-{value}
Flex direction bcq-flex-{bp}-{value}
Text align bcq-text-{bp}-{start|center|end}
Float bcq-float-{bp}-{start|end|none}
Margin, padding bcq-m{sides}-{bp}-{n}, bcq-p{sides}-{bp}-{n}

Customize

$container-queries-breakpoints: (sm: 30em, md: 48em, lg: 62em, xl: 75em, xxl: 90em);

Frozen builds of this version are in the package: bootstrap-container-queries/dist/v3/bootstrap-container-queries.css.

Good to know

Live demo

Resize the box below (drag its corner) or use the buttons.

bcq-sm-6 bcq-md-4 bcq-lg-3
bcq-sm-6 bcq-md-4 bcq-lg-3
bcq-sm-6 bcq-md-4 bcq-lg-3
hide on sm and wider screens
hide on screens smaller than sm
hide on lg and wider screens
hide on screens smaller than md
hide on lg and wider screens
hide on screens smaller than lg
text start < sm < text end
text start < md < text end
text start < lg < text end
float start < sm < float end
float start < md < float end
float start < lg < float end
flex direction column < lg < flex direction column-reverse