Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Positioning and Stacking

The isolation property

Reference for the CSS isolation property: use isolate to create a stacking context without side effects, contain z-index values and limit blend modes.

The isolation property decides whether an element forms its own stacking context. With isolation: isolate it always does, with no other visual side effects. With the default auto, a stacking context only appears if something else triggers it, such as opacity below 1 or a transform.

The point is containment. Inside an isolated element, z-index values and blend modes are resolved locally, so a component's internal z-index: 10 can no longer leak out and fight with the rest of the page.

CSS
.card { isolation: isolate; }

Try it

Isolating a blend mode

The red layer hangs over the edge of the blue box. In the first case the blue box has no stacking context of its own, so the red layer blends with everything beneath it, and the overhang mixes with the yellow background. In the second, blending stops at the isolated group: the red mixes with the blue, and the overhang stays plain red.

Syntax

CSS
isolation: auto | isolate;
  • Initial value: auto
  • Applies to: all elements
  • Inherited: no
  • Animatable: no (discrete)
  • Computed value: as specified

Values

Value Description
auto A stacking context is created only if another property requires it.
isolate The element always creates a new stacking context.

Usage notes

  • Cleaner than hacks. Before isolation, people wrote position: relative; z-index: 0 just to get a context. isolate says what you mean and does not need a positioned element.
  • Stops z-index leaks. Put it on components such as cards, menus or widgets whose children use z-index, especially layered pseudo-elements with negative values.
  • Contains blending. mix-blend-mode and background-blend-mode do not reach beyond the nearest stacking context, so isolate limits their effect.
  • A context is not a containing block. It does not make absolute children position against the element; use position: relative for that.
  • Opposite goal. isolation cannot remove a context created by transform, opacity or others.

Browser support

Supported in all modern browsers since about 2018.