Skip to main content

Container Queries

Style an element by the width of its container instead of the viewport.

View as Markdown
baselinewidely

Using Container Queries

Mark the parent with ct:is and prefix a child's class with @c:. It applies once the container reaches that width.

<div className="ct:is">
  <h2 className="fs:md @c:sm:fs:xl">Recent files</h2>
</div>

The same card can sit in a narrow sidebar & a wide page & lay itself out for each, because it measures the space it is given.

Breakpoints

@c: takes every breakpoint name, including the ones you add with theme.screens.

PrefixContainer WidthCSS Rule
@c:xs32 rem (512 px)@container (min-width: 32rem)
@c:sm40 rem (640 px)@container (min-width: 40rem)
@c:md48 rem (768 px)@container (min-width: 48rem)
@c:lg64 rem (1024 px)@container (min-width: 64rem)
@c:xl80 rem (1280 px)@container (min-width: 80rem)
@c:xxl96 rem (1536 px)@container (min-width: 96rem)

Stacking

A container query stacks with any other variant, like every at-rule.

<a className="o:100 @c:md:h:o:80">Open folder</a>