isolation CSS Property Demo - Online Control Stacking Context
Use isolation: isolate to contain mixâblendâmode and filters. See the visual difference with and without. Quick demo.
UD5 Toolkit
contain Property Demo
Interactive visualization of layout, paint & size isolation in real-time
Observe how contain:size prevents the container from growing with its children.
contain:size, the container's height is dictated by its children. With it, the height collapses to 0 unless explicitly set.
See how contain:paint clips overflow and contain:layout contains floats.
This text wraps around the float. contain:layout creates a BFC and contains the float entirely.
contain:paint clips it. contain:layout makes the container self-contained for floats.
CSS contain tells the browser what the element's subtree is independent of, enabling powerful optimizations.
contain:layout creates a formatting context boundary. Internal layout changes don't trigger external reflows.
contain:paint acts like a super overflow:hidden â it also creates a stacking context and containing block.
contain:size lets the browser skip subtree size calculations â ideal for virtual scrolling & lazy-loaded widgets.
contain property and why should I use it?
contain property allows you to indicate that an element's subtree is independent from the rest of the page. This gives browsers critical hints to optimize rendering performance. By isolating layout, paint, or size calculations, the browser can skip expensive recalculations when only the contained subtree changes. It's one of the most impactful CSS properties for web performance, especially for complex UIs, widget-heavy pages, and infinite scroll implementations. Values include none, size, layout, paint, style, content (size+layout+paint), and strict (all four).
contain:paint and overflow:hidden?
contain:paint goes significantly further. It creates a new stacking context, establishes a containing block for absolutely positioned descendants, and acts as a paint boundary. This means the browser can paint the element independently â if it hasn't changed, its pixels can be reused from a cached layer. overflow:hidden only clips content without providing these additional isolation guarantees. For performance-critical rendering, contain:paint is the stronger choice.
contain:size work and when does the container collapse?
contain:size tells the browser that the element's size does not depend on its children. For block-level elements without an explicit height, the height collapses to 0 (padding and borders remain). The width typically remains 100% of the parent for block elements in normal flow. This is perfect for virtual scroll containers, lazy-loaded widgets with known dimensions, and carousel items where you want to pre-allocate space. Always set explicit width and height (or use content-visibility:auto which applies size containment automatically) when using contain:size to avoid unexpected collapsing.
contain:layout actually isolate?
contain:layout creates a formatting context boundary (similar to a BFC â Block Formatting Context). This means: (1) Internal layout changes (like a child growing) won't affect elements outside the container â no external reflow. (2) Floats inside the container are contained and won't escape. (3) Margin collapsing between the container's children and external elements is prevented. (4) The container acts as a baseline isolation point. It's ideal for independent UI components like modals, dropdown panels, and sidebar widgets where internal layout stability is desired.
contain and content-visibility?
content-visibility:auto is a powerful CSS property that automatically applies contain:size layout paint (equivalent to contain:content) to elements that are off-screen. This allows the browser to skip rendering work for off-screen content entirely, dramatically improving page load and scroll performance. You can think of contain as the low-level primitive, and content-visibility as the high-level, automated application of containment. Use contain for fine-grained control over always-visible elements, and content-visibility:auto for below-the-fold content sections.
contain value gives the best performance?
contain:strict applies all four containment types (size, layout, paint, style) and offers the maximum isolation. However, it's also the most restrictive. For most practical use cases, contain:content (equivalent to size layout paint) provides an excellent balance of performance and flexibility. It enables all major optimizations while being less restrictive than strict. The key is choosing the least restrictive value that still accurately describes your element's independence â over-containing can break layouts just as under-containing misses optimization opportunities.
contain safe to use on any element?
contain:size will collapse an element's height to 0 if no explicit height is set â this can break layouts unexpectedly. contain:paint creates a new stacking context which may affect z-index behavior. contain:layout affects how floats and margins interact. Always test thoroughly after applying containment. Start with contain:layout or contain:paint individually before combining them, and use browser DevTools to verify the element still renders as expected across all viewport sizes.
contain badge next to elements that have containment applied. In the Rendering tab (available via the three-dot menu â More tools â Rendering), you can enable "Layer borders" to visualize paint-contained layers. The Performance panel also shows reduced layout and paint work for contained elements. Firefox's DevTools similarly highlights containment in the inspector. When things look wrong, temporarily set contain:none to confirm whether containment is the culprit.
Use isolation: isolate to contain mixâblendâmode and filters. See the visual difference with and without. Quick demo.
Adjust margin, border, padding, and content sizes interactively and see the rendered box model. Get the exact CSS. Teach or learn layout.
Enter container width, number of items, gap, and flexâbasis. See the resulting sizes instantly. Plan your flex layout.
Design a custom focus indicator with outline, offset, and boxâshadow. Preview on interactive elements. Copy the CSS.
Browse the builtâin styles that browsers apply to HTML elements. Understand why your page looks different. Static reference.
Visually experiment with Flexbox container and item properties. See the layout update in real time and copy the CSS. Learn by doing, fully interactive.
Design neumorphic elements by adjusting boxâshadow parameters. Realâtime preview and CSS output. For modern soft UI interfaces.
Create CSS maskâimage effects with custom shapes, gradients, and SVGs. Visually see the mask applied to an image. Copy the CSS.
Understand @layer by visually ordering style layers and seeing which rules win. Fix specificity battles. Modern CSS architecture.
Paste your CSS and see warnings for properties that have limited browser support. Links to CanIUse. Modernize safely.
Create a 'SALE' or 'NEW' corner ribbon in pure CSS. Adjust colors, position, and text. Great for eâcommerce.
Design layered box shadows interactively and get the CSS code in real time. Adjust offset, blur, spread, and color. Essential tool for UI designers.
Generate a random HTML/CSS card with different box model properties. Inspect and guess the size. For learners.
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.
See how scrollâpadding and scrollâmargin affect the position of elements when using anchor links or scrollâsnap. Visual.
Build a custom CSS reset by toggling which elements to normalize. Copy the resulting stylesheet. Lean and clean.
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.
Visually configure scrollâsnap containers and items. Adjust alignment, stop behavior, and padding. Copy the clean CSS instantly.
Create inner shadows for a pressed or sunken effect. Visually adjust and copy the CSS. Learn inset.
Design a tooltip that appears on hover without JavaScript. Choose positioning, arrow, and animation. Copy the clean HTML/CSS.
Design a fully styled scrollbar with colors, width, and border radius. Get the CSS for Chrome and Firefox.
Design a pure CSS tooltip with custom text, position (top/bottom/left/right), and arrow. Copy the clean code.
Learn how to let content extend a few pixels beyond a clip boundary with overflowâclipâmargin. Interactive playground.
Use anchor positioning to perfectly center a popover relative to its anchor. No JavaScript. See the modern approach.
Upload an image and generate the CSS to use it as a custom mouse cursor. Test it live. Fun for personal websites.
Build a .editorconfig file by setting indentation, charset, and endâofâline rules for your project. Keep all contributors aligned.
Generate a range of tints and shades from a single hex color. Ideal for data visualization, UI design systems, and Tailwind custom palette creation. Local tool.
Paste code and generate a beautiful, syntaxâhighlighted PNG image. Choose theme and window style. Shareable code pics.