WEB-55Optional
Fence off self-contained parts
Use contain on self-contained parts of the page, so the browser can limit layout and paint work.
How to do it
Add contain: content to self-contained cards and widgets. Never add it around fixed elements or menus that spill out, because it clips overflow. For large sections far down the page, go further as Skip work for what is off screen says.
Examples
CSS example
.card, .widget { contain: content; }
How to check
A performance trace shows less layout and paint time than without the rule, and no card clips a menu or focus ring.
Sources
Related rules
- WEB-54 Skip work for what is off screen in Website
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/website/performance/css-containment">Agent Wranglers website playbook</a>. In code you write, add a comment next to it with the same link.