CSS contain Property Demo - Online Layout & Paint Isolation
Toggle contain: strict, content, paint, layout and see how it affects rendering. Understand isolation for faster pages.
UD5 Toolkit
isolation Property Demo
Visualize how isolation: isolate creates a new stacking context, containing child z-index values within a component. Compare with isolation: auto (default) where children can "escape" their parent's stacking level.
isolation: isolate, the overlay always covers the badge because the card's stacking context is isolated.
The child element's z-index: 10 participates in the root stacking context. It can appear above sibling elements (like the overlay at z-index: 5) even though it's nested inside the card. This is often unexpected and causes z-index wars in complex UIs.
isolation: isolate creates a new stacking context on the card.
The badge's z-index: 10 is now scoped within the card.
External elements (like the overlay) are compared against the card's stacking level — not its children.
This encapsulates z-index behavior.
Prevent internal z-index values from leaking out and conflicting with other components on the page.
Ensure modals and overlays properly cover third-party widgets or dynamically loaded content.
Use negative z-index inside a component for background effects without the element disappearing behind the page.
isolation property?
isolation property controls whether an element creates a new
stacking context. It accepts two values: auto (default, no new stacking context)
and isolate (creates a new stacking context). When set to isolate, all child
elements' z-index values are contained within the element, preventing them from interacting with
elements outside in the stacking order. This is part of the
Compositing and Blending specification.
isolation: isolate differ from using z-index?
z-index value on a positioned element also creates a stacking context, but it
simultaneously positions that element in the stacking order.
isolation: isolate creates a stacking context without affecting the element's
own stacking level — it stays at z-index: auto. This is cleaner when you only want
to contain children without repositioning the parent. Also, isolation works on
non-positioned elements (e.g., display: flex containers).
isolation: isolate in real projects?
isolation: isolate when:isolation: isolate affect performance?
isolation: isolate has minimal performance impact.
In fact, it can improve rendering performance in some cases by helping the browser
optimize compositing layers. Each stacking context may become its own compositing layer,
which can reduce repaint areas. However, excessive stacking contexts (hundreds) could
increase memory usage. Use it judiciously on component boundaries, not on every element.
isolation and opacity / transform?
opacity (less than 1), transform, filter,
perspective, clip-path, and will-change also create stacking
contexts — even without isolation: isolate. However, these properties come with
side effects (visual changes, performance implications).
isolation: isolate is the cleanest, most explicit way to create a
stacking context when you don't need those other effects. It's a single-purpose tool.
isolation?
isolation property has excellent browser support. It's supported in
all modern browsers: Chrome (41+), Firefox (36+), Safari (8+), Edge (79+), and Opera (28+).
It's safe to use in production without polyfills. For Internet Explorer, it's not supported (IE
reached end-of-life in June 2022). You can confidently use it in any modern web project.
isolation: isolate fix all z-index problems?
isolation: isolate is a powerful tool but not a universal fix. It
contains child z-indices within a component, but it doesn't change how the
component itself stacks relative to siblings. You still need to manage z-index values for
parent-level elements. Think of it as scoping z-index: it prevents internal
values from leaking out, but external stacking relationships still need proper management.
isolation: isolate, non-auto z-index,
opacity < 1, transforms, filters, or will-change.
/* Create a stacking context cleanly */ .component { isolation: isolate; } /* Alternative: using z-index (also positions) */ .component { position: relative; z-index: 0; /* also creates stacking context */ }
/* Values */ isolation: auto; /* default */ isolation: isolate; /* new stacking context */ isolation: inherit; isolation: initial; isolation: unset;
Toggle contain: strict, content, paint, layout and see how it affects rendering. Understand isolation for faster pages.
Create CSS mask‑image effects with custom shapes, gradients, and SVGs. Visually see the mask applied to an image. Copy the CSS.
Design a custom focus indicator with outline, offset, and box‑shadow. Preview on interactive elements. Copy the CSS.
Understand @layer by visually ordering style layers and seeing which rules win. Fix specificity battles. Modern CSS architecture.
Design neumorphic elements by adjusting box‑shadow parameters. Real‑time preview and CSS output. For modern soft UI interfaces.
Visually experiment with Flexbox container and item properties. See the layout update in real time and copy the CSS. Learn by doing, fully interactive.
Interactively add and adjust multiple box shadows on a sample element. Drag sliders for offset, blur, spread, and color. Copy the clean CSS code instantly.
Set the inset property and see its logical shorthand equivalents. Copy the modern CSS for absolutely positioned elements.
Adjust margin, border, padding, and content sizes interactively and see the rendered box model. Get the exact CSS. Teach or learn layout.
Build a custom CSS reset by toggling which elements to normalize. Copy the resulting stylesheet. Lean and clean.
Design layered box shadows interactively and get the CSS code in real time. Adjust offset, blur, spread, and color. Essential tool for UI designers.
Learn how to let content extend a few pixels beyond a clip boundary with overflow‑clip‑margin. Interactive playground.
Paste your CSS and see warnings for properties that have limited browser support. Links to CanIUse. Modernize safely.
Generate a random HTML/CSS card with different box model properties. Inspect and guess the size. For learners.
Create inner shadows for a pressed or sunken effect. Visually adjust and copy the CSS. Learn inset.
Paste HTML/CSS snippets or enter properties to test how z‑index and stacking contexts interact. Real‑time example.
Enter container width, number of items, gap, and flex‑basis. See the resulting sizes instantly. Plan your flex layout.
Create a 'SALE' or 'NEW' corner ribbon in pure CSS. Adjust colors, position, and text. Great for e‑commerce.
Design a tooltip that appears on hover without JavaScript. Choose positioning, arrow, and animation. Copy the clean HTML/CSS.
Browse the built‑in styles that browsers apply to HTML elements. Understand why your page looks different. Static reference.
Use anchor positioning to perfectly center a popover relative to its anchor. No JavaScript. See the modern approach.
Visually configure scroll‑snap containers and items. Adjust alignment, stop behavior, and padding. Copy the clean CSS instantly.
Set up a Shared Worker that shares state across multiple browser tabs. Counter and messaging demo. Advanced web.
Design a pure CSS tooltip with custom text, position (top/bottom/left/right), and arrow. Copy the clean code.
Design a fully styled scrollbar with colors, width, radius, and hover effects. Supports both ::-webkit‑scrollbar and Firefox scrollbar‑width.
Set tab‑size to any number and see how tabs are displayed in a pre element. Essential for code snippets.
Design a fully styled scrollbar with colors, width, and border radius. Get the CSS for Chrome and Firefox.
See how scroll‑padding and scroll‑margin affect the position of elements when using anchor links or scroll‑snap. Visual.
Upload an image and generate the CSS to use it as a custom mouse cursor. Test it live. Fun for personal websites.
Type raw HTML and see the escaped version, then see how it renders when unescaped. Understand encoding better.