0
0
CSSmarkup~8 mins

Hidden, scroll, auto in CSS - Performance & Optimization

Choose your learning style9 modes available
Performance: Hidden, scroll, auto
MEDIUM IMPACT
These CSS overflow properties affect how content overflow is handled, impacting layout stability and rendering performance.
Handling overflow content in a container
CSS
div {
  overflow: scroll;
  height: 200px;
}
Using overflow: scroll always shows scrollbars, preventing layout shifts caused by scrollbar appearance changes.
📈 Performance Gainavoids layout shifts, reduces reflows related to scrollbar toggling
Handling overflow content in a container
CSS
div {
  overflow: auto;
  height: 200px;
}
Using overflow: auto can cause layout shifts when scrollbars appear or disappear dynamically, leading to CLS issues.
📉 Performance Costtriggers layout recalculation and repaint when scrollbar toggles
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
overflow: autoMinimal DOM changesReflow triggered when scrollbar appears/disappearsMedium paint cost due to scrollbar rendering[!] OK
overflow: scrollMinimal DOM changesSingle reflow on initial layoutConsistent paint cost, no layout shifts[OK] Good
overflow: hiddenMinimal DOM changesNo reflows from scrollbar changesLower paint cost by clipping overflow[OK] Good
overflow: visibleMinimal DOM changesNo scrollbar reflows but possible layout shiftsHigher paint cost due to overflow content[X] Bad
Rendering Pipeline
Overflow properties affect the Layout and Paint stages by controlling how content outside container bounds is handled and whether scrollbars are rendered.
Layout
Paint
Composite
⚠️ BottleneckLayout
Core Web Vital Affected
CLS
These CSS overflow properties affect how content overflow is handled, impacting layout stability and rendering performance.
Optimization Tips
1Use overflow: scroll to avoid layout shifts caused by scrollbar toggling.
2Use overflow: hidden to clip content and reduce paint cost.
3Avoid overflow: auto if dynamic scrollbar appearance causes layout instability.
Performance Quiz - 3 Questions
Test your performance knowledge
Which overflow property setting helps prevent layout shifts caused by scrollbar appearance?
Aoverflow: visible
Boverflow: auto
Coverflow: scroll
Doverflow: hidden
DevTools: Performance
How to check: Record a performance profile while interacting with the container that has overflow styles. Look for layout and paint events triggered when scrollbars appear or content changes.
What to look for: Look for layout recalculations and paint events that coincide with scrollbar toggling or content overflow changes indicating performance impact.