0
0
Bootsrapmarkup~8 mins

Visibility utilities in Bootsrap - Performance & Optimization

Choose your learning style9 modes available
Performance: Visibility utilities
MEDIUM IMPACT
Visibility utilities affect how elements are shown or hidden, impacting rendering and layout calculations during page load and interaction.
Hiding elements without causing layout shifts
Bootsrap
class="invisible"
Keeps element in layout but hides it visually, preventing layout shifts.
📈 Performance GainNo reflow triggered, prevents CLS, smoother user experience
Hiding elements without causing layout shifts
Bootsrap
class="d-none"
Completely removes the element from layout, causing reflow and potential layout shifts when toggled.
📉 Performance CostTriggers 1 reflow per element toggle, causing noticeable CLS on many elements
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Using d-none (display:none)Removes element from layoutTriggers reflowPaint cost moderate[X] Bad
Using invisible (visibility:hidden)Element remains in layoutNo reflowPaint cost low[OK] Good
Rendering Pipeline
Visibility utilities change CSS properties that affect layout and paint stages. Using display:none triggers layout recalculation and reflow, while visibility:hidden only affects paint without layout changes.
Style Calculation
Layout
Paint
⚠️ BottleneckLayout (reflow) when using display:none
Core Web Vital Affected
CLS
Visibility utilities affect how elements are shown or hidden, impacting rendering and layout calculations during page load and interaction.
Optimization Tips
1Avoid toggling display:none frequently to prevent layout recalculations.
2Use visibility:hidden to hide elements without causing layout shifts.
3Combine opacity:0 with pointer-events:none for smooth visual hiding without reflow.
Performance Quiz - 3 Questions
Test your performance knowledge
Which visibility utility causes layout recalculation and potential layout shifts?
Ad-none (display:none)
Binvisible (visibility:hidden)
Copacity-0
Dfade
DevTools: Performance
How to check: Record a performance profile while toggling visibility utilities. Look for layout (reflow) events and paint times.
What to look for: Presence of layout recalculations indicates costly visibility changes; absence means better performance.