Widely availableSupported across all major browsers. Safe to use in production.

Overview

The contain: size CSS declaration sets an element's dimensions exclusively by its height and width properties, ignoring its contents and descendants. This permits the browser to avoid slower layout calculations.

Browser support

Feature Desktop Mobile
Chrome
Edge
Firefox
Safari
Chrome Android
Safari iOS
css.properties.contain.size
52
79
69
15.4
52
15.4
1+Supported (version) Not supported Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)

Syntax

CSS
.fixed-widget {
  contain: size;
  width: 300px;
  height: 200px;
}

Live demo

Contain: Size(locksize)

CSS Contain: size(locksize) demo.

PreviewFullscreen

Contain: size(empty. state)

CSS Contain: size(empty. state) demo.

PreviewFullscreen

containment none(comparison)

CSS containment none(comparison) demo.

PreviewFullscreen

Use cases

  • Using Size containment

    The contain: size CSS declaration sets an element's dimensions exclusively by its height and width properties, ignoring its contents and descendants. This permits the browser to avoid slower layout calculations.

Cautions

  • May not be supported in older browsers.

Accessibility

  • Make sure visual changes are conveyed appropriately to assistive technology.

Powered by web-features