Skip to main
blockquote with magenta background and polygonal clip-path

Container Queries: a Quick Start Guide

Now is the time to begin experimenting with a long requested layout tool.

The @container query, that elusive feature developers have been requesting and proposing for years, has finally made its debut in a browser. Well, sort of. Here we’ll explain what container queries are, how they work, and what other features they might come with once fully supported in browsers.

In the latest version of Chrome Canary, the most recent @container query proposal is available for use behind an experimental flag. Developed by OddBird’s own Miriam Suzanne, the draft builds upon the ideas previously proposed by other web standards experts like David Baron, who wrote the original draft.

@Media queries sparked a responsive design revolution by allowing authors to change the style of elements based on the size of the entire viewport. Up until now, what could not be done was changing the style of an element based on the size of one of its nearest containers.

The proposed @container query syntax feels a lot like writing a @media query, but a main difference is that a @container query has to be implemented in two parts.

In this demo (which only works in the latest version of Chrome Canary), a blockquote is styled differently depending on the size of its container.

See the Pen Container Queries with Block Quotes by @dvdherron on CodePen.

Define a containment context

To achieve this, first define a containment context. This lets the browser know which container to query against later and how exactly to query that specific container.

section {
  container-type: inline-size;

The container-type[1] property turns on containment for the selected elements, allowing for the testing of aspects such as style, size, and state.

The inline-size value specifies that, in this case, queries will be made against the containing element’s inline axis. Layout and size[2] containment are applied automatically as well.

(Block-size is also being considered as a containment type in the new proposal. Inline-size seemed to satisfy more use-cases, so is being developed first.)

Containers can also be named:

section {
  container-name: demo;
  container-type: inline-size;

And the container-type and container-name properties can be combined by using the container shorthand property:[3]

section {
  container: demo / inline-size;

 @container demo (min-width: 30em) {
   .element {
      /* styles to apply */

Apply @-rules at desired breakpoints

Now that a containment context has been defined, the @container rule is used to tell the browser when and how styles should change inside each container.

With a narrow parent container, the blockquote features the image stacked on top of the text.

The profile image sits on top of the quote in narrow containers.

At the first breakpoint, the layout for the blockquote changes so that the profile image moves from being above the quote to sitting next to it, and the text describing the speaker gets a heavier weight applied.

The profile image changes position at the first breakpoint to sit next to the quote.
/* change styles according to container size */
@container (min-width: 35em) {

  .quote {
    grid-gap: 1rem;
    grid-template: "media quote" auto/ max-content 1fr;

  .media {
    align-items: center;

  .source {
    font-weight: bold;

At the second breakpoint, the size of the text for the quote and the attribution grows, the background changes color, and the overall shape of the blockquote changes by way of a clip-path.

At a wider breakpoint, the blockquote gets a clip-path and a different background color.
@container (min-width: 60em) {

  .quote {
    --quote-size: 1.5rem;
    --quote-background: darkmagenta;
    clip-path: polygon(
      -0.04% 100.6%,
      1.12% -0.52%,
      95.65% 11.18%,
      96.46% 90.05%
    padding: 1.25em 3em;
    max-width: unset;

  .source {
    font-size: 1.1rem;

Any styles inside of one of these @container blocks will be applied when the container fulfills the condition of the query.

Just as with @media queries, authors can write as many @container queries as needed.

With each blockquote sitting in a different sized container, they all look slightly different, at the same viewport size.

The same blockquote component gets styled differently depending on its container size.

It’s still very early in the proposal process, so a lot regarding how container queries work could change.

Bookmark Miriam’s scratch site for updates: Miriam’s CSS Sandbox.

To participate in discussions and implementation questions related to container queries, visit this project board: Open Issues & Work on the Contain 3 Spec.

Follow these steps to get started experimenting and making your own demos:

The OddBird team would love to see what you come up with. Tag us on Twitter with a link to whatever you create. In the meantime, check out our collection of demos on CodePen for inspiration.

  1. Syntax for establishing a containment context was updated July 14, 2021 to use the new container-type and container-name properties instead of contain. ↩︎

  2. A previous version of this article listed style and layout as required values for the contain property when establishing a containment context. These values are now automatically applied when using the new container-type and container-name properties. Updated July 14, 2021. ↩︎

  3. The two values of the shorthand were originally reversed, with container-type and then container-name. Updated August 18, 2022. ↩︎

Upcoming Workshop

Mia from behind,
standing at a laptop -
speaking to a conference audience
and gesturing to one side

Cascading Style Systems

A workshop on resilient & maintainable CSS

New CSS features are shipping at an unprecedented rate – cascade layers, container queries, the :has() selector, subgrid, nesting, and so much more. It’s a good time to step back and understand how these tools fit together in a declarative system – a resilient cascade of styles.

Register for the October workshop »

Recent Articles

  1. A dog zooming by the camera, up-close, body twisted and eyes wide as it circles a grass yard
    Article post type

    Zoom, zoom, and zoom

    The three types of browser (and CSS!) magnification

    I’m working on an article about fluid typography, and relative units. But instead, I fell down this rabbit hole – or a cleverly-disguised trap? – trying to understand ‘zoom’ in the browser (not Zoom™️ the software). Since I couldn’t find any up-to-date articles on the subject, I thought I shoul…

    see all Article posts
  2. A rusty anchor hanging with the sea in the background.
    Article post type

    Updates to the Anchor Position Polyfill

    Catching up to the spec

    Our sponsors are supporting the continued development of the CSS Anchor Positioning Polyfill. Here’s a summary of the latest updates.

    see all Article posts
  3. A back hoe on the bank of the Suez, trying to free the Ever Given cargo ship
    Article post type

    Learn Grid Now, Container Queries Can Wait

    Take your time with new CSS, but don’t sleep on the essentials

    Several people have asked recently why container queries aren’t being used more broadly in production. But I think we underestimate the level of legacy browser support that most companies require to re-write a code-base.

    see all Article posts