Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Container Queries and Logical Properties

The container property

Reference for the CSS container shorthand: set container-name and container-type in one declaration to enable @container queries, with syntax and examples.

The container property is a shorthand for container-name and container-type. It turns an element into a query container, so that its descendants can be styled with @container rules based on the container's size rather than the size of the viewport.

The name goes first, then a slash, then the type. Both parts are optional in practice: you can give only a name, or you can use container-type alone.

CSS
.card-list {
  container: cards / inline-size;
}

@container cards (min-width: 40rem) {
  .card { display: flex; }
}

Try it

The same card in two containers

Both cards use the same CSS. Each one asks its own container how wide it is.

Syntax

CSS
container: <container-name> [ / <container-type> ]
container: none
  • Initial value: none / normal (no name, type normal)
  • Applies to: all elements
  • Inherited: no
  • Animatable: no
  • Computed value: as for each of the longhand properties

Values

Value Description
<name> One or more custom identifiers that @container rules can use to pick this container. Without a slash, the type stays normal.
/ <type> normal, size or inline-size. See container-type.
none Resets both longhands: not a container, no name.

Examples: container: sidebar / inline-size;, container: panel / size;, and beware that container: inline-size; is not a type: a lone word is read as a name, so it creates a container called "inline-size" with type normal. Write container-type: inline-size when you do not need a name.

Usage notes

  • A container never styles itself. @container rules style the container's descendants. Put the container on a wrapper and style the children, as in the example.
  • The type decides the cost. inline-size is what most layouts need. It makes the container's width independent of its content, so give it a width through its parent (block, flex or grid sizing).
  • Shorthand resets. Writing container: cards sets the type to normal, which cancels an earlier container-type: inline-size on the same element. Declare the longhands separately if you want to combine them in different rules.
  • Names are optional but useful. Without a name, a query matches the nearest ancestor container that fits the query features. A name avoids surprises when containers nest.
  • Units. Inside a container you can use the container query units from cqw, cqh, cqi and cqb.

Browser support

Container queries and the container shorthand are supported in all current major browsers and are part of Baseline; check a compatibility table for older versions.