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.
.card { isolation: isolate; }
Try it
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
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 wroteposition: relative; z-index: 0just to get a context.isolatesays 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-modeandbackground-blend-modedo not reach beyond the nearest stacking context, soisolatelimits their effect. - A context is not a containing block. It does not make absolute children position against the element; use
position: relativefor that. - Opposite goal.
isolationcannot remove a context created bytransform,opacityor others.
Browser support
Supported in all modern browsers since about 2018.
Related
z-indexmix-blend-modeposition- Lesson: CSS z-index