0
0
CSSmarkup~8 mins

Background position in CSS - Performance & Optimization

Choose your learning style9 modes available
Performance: Background position
MEDIUM IMPACT
Background position affects how the browser paints background images, impacting paint and composite stages.
Positioning a background image efficiently
CSS
background-position: center center;
Using simple keywords lets the browser optimize painting and avoid unnecessary recalculations.
📈 Performance Gainreduces repaints and layout shifts, improving visual stability
Positioning a background image efficiently
CSS
background-position: calc(50% + 10px) calc(50% + 10px);
Using complex calculations forces the browser to recalculate styles and triggers repaints on resize or animation.
📉 Performance Costtriggers multiple style recalculations and repaints on viewport changes
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
background-position: calc(50% + 10px) calc(50% + 10px);none0 but triggers style recalculationhigh paint cost on resize[X] Bad
background-position: center center;none0low paint cost[OK] Good
Rendering Pipeline
Background position affects the Style Calculation and Paint stages. Complex values cause more frequent style recalculations and repaints, increasing CPU usage and causing layout shifts.
Style Calculation
Paint
Composite
⚠️ BottleneckPaint stage is most expensive due to redrawing background images with complex positions.
Core Web Vital Affected
CLS
Background position affects how the browser paints background images, impacting paint and composite stages.
Optimization Tips
1Use simple keywords like 'center', 'top', or 'left' for background-position.
2Avoid complex calculations in background-position to reduce repaints.
3Test background-position changes with browser DevTools Performance panel.
Performance Quiz - 3 Questions
Test your performance knowledge
Which background-position value is best for reducing repaints?
Acenter center
Bcalc(50% + 10px) calc(50% + 10px)
C50% 50%
Dauto auto
DevTools: Performance
How to check: Record a performance profile while resizing or animating the background. Look for style recalculations and paint events related to background-position.
What to look for: High number of style recalculations and paint events indicate inefficient background-position usage.