Performance: Overflow handling
Controls how content that exceeds container size is displayed, impacting layout stability and rendering speed.
Jump into concepts and practice - no test required
<div class="w-64 h-32 overflow-auto"> <p class="whitespace-normal">Very long text that overflows but is scrollable inside the container, preventing layout shifts.</p> </div>
<div class="w-64 h-32"> <p class="whitespace-normal">Very long text that overflows the container without any overflow control, causing layout shifts.</p> </div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No overflow control (content spills) | High (container resizes) | Multiple reflows on content change | High paint cost due to layout shifts | [X] Bad |
| Overflow-auto with scrollbars | Low (fixed container size) | Single reflow | Lower paint cost, stable layout | [OK] Good |
| Overflow-hidden clipping content | Low (fixed container size) | Single reflow | Low paint cost, no layout shifts | [OK] Good |
overflow-hidden do to the content inside a container?overflow-hidden tells the browser to cut off any content that extends beyond the container edges.overflow-auto or overflow-scroll, it does not show scrollbars or resize content.overflow-auto adds scrollbars only if content is bigger than the container.overflow-scroll always shows scrollbars, overflow-hidden hides overflow, and overflow-visible shows overflow without scrollbars.<div class="w-40 h-20 overflow-scroll border border-gray-400"> <p>This is a very long text that will not fit inside the box.</p> </div>
overflow-scroll which always shows scrollbars.overflow-auto instead of overflow-hidden. What problem will you see?overflow-auto shows scrollbars if content is bigger, while overflow-hidden hides overflow without scrollbars.overflow-y-auto adds scrollbars vertically only when needed, and overflow-x-hidden hides horizontal overflow.overflow-auto adds scrollbars on both axes, overflow-scroll always shows scrollbars on both axes, and overflow-hidden hides all overflow.