CSS container Property
Description
The container property lets an element establish a container context that descendant rules and container queries can target; rather than using the viewport as the reference for responsive conditions, that element becomes the reference frame for evaluating size- or other container-based queries. It functions as a high-level, declarative way to say “this element should behave as a self-contained layout scope” so that components can adapt based on the size and characteristics of their own container instead of the entire page.
When you apply the container property, you are conceptually assigning both an identity and a type to the element so that query rules can match against it. Those two aspects are reflected by the related longhand properties container-name and container-type, which control how a container is referenced and what aspects of the element (size, style containment, etc.) are used for query evaluation. Container-aware rules (for example, with the container query at-rule) then select styles based on that referenced container rather than the viewport, enabling truly component-scoped responsive behavior.
Beyond scoping, the semantics of container interact with layout and performance: declaring a container can limit the area of layout recalculations and restrict what gets considered when evaluating queries, which can improve rendering efficiency for componentized UIs. It is often used alongside containment strategies to create predictable, encapsulated components; the contain property is frequently mentioned in the same design patterns because it also governs how an element’s internal layout and rendering are isolated from the outside.
In practical design terms, the container property encourages building smaller, self-sufficient components that respond to their immediate context — the container — instead of relying on global viewport breakpoints. That shifts responsive design from a page-level approach to a component-level approach, simplifying reuse and composition: a component styled to adapt to its container will behave consistently whether it’s placed in a sidebar, a card, or a full-width section.
Definition
- Initial value
- See individual properties
- Applies to
- all elements
- Inherited
- no
- Computed value
- See individual properties
- Animatable
- See individual properties
- JavaScript syntax
- object.style.container
Syntax
container: <container-name> | <container-type>
Values
- <container-name>A case-sensitive name for the containment context. More details on the syntax are covered in the container-name property page.
- <container-type>The type of containment context. More details on the syntax are covered in the container-type property page.
Example
Browser Support
The following information will show you the current browser support for the CSS container property. Hover over a browser icon to see the version that first introduced support for this CSS property.
This property is supported by all modern browsers.
Desktop
Tablets & Mobile
Last updated by CSSPortal on: 1st January 2026
