Hereβs a comprehensive table of CSS properties categorized by their impact on browser rendering performance, specifically focusing on Layout, Paint, and Composite:
Layout: Calculate the size and position of elements on the page.
Paint: Draw the page into graphical layers - essentially individual images that make up the page.
Composite: Draw these layers to the viewport.
Properties
clip-path,opacity,transform,z-index,visibility,filter, are best for performing web animations
| CSS Property | Layout | Paint | Composite | Notes |
|---|---|---|---|---|
width, height
|
β | β | β | Affects element and child layout |
margin, padding
|
β | β | β | Triggers layout changes |
border |
β | β | β | Repaints element boundary |
box-shadow |
β | β | β | Complex paints for shadows |
top, left, right, bottom
|
β | β | β | Reflows and triggers layout |
position |
β | β | β | Changes element's positioning model |
display |
β | β | β | Can remove or reflow elements entirely |
color, background-color
|
β | β | β | Simple paint update |
background-image |
β | β | β | Complex paint updates |
transform |
β | β | β | GPU accelerated; efficient compositing |
opacity |
β | β | β | Composited efficiently |
z-index |
β | β | β | Layer stacking order |
visibility |
β | β | β | Affects visibility without layout |
overflow |
β | β | β | Layout affected by scrollbars |
clip-path |
β | β | β | Efficient compositing |
border-radius |
β | β | β | Paint complexity increases |
filter |
β | β | β | GPU optimized for modern browsers |
box-sizing |
β | β | β | Changes size calculations |
font-size, font-family
|
β | β | β | Relayout and repaint text |
line-height, letter-spacing
|
β | β | β | Text rendering changes |
Legend:
β : Triggers the specified phase
β: Does not trigger the phase
Performance Tip:
Prefer transform and opacity changes for animations instead of properties like
top,left, orwidthto avoid costly layout recalculations.Reduce unnecessary paints and layout reflows by using GPU-accelerated properties (
transform,opacity).transformandopacityare cheapest to render in all browsers. Browsers are improving the rendering performance of other styles (and SVG) all the time, withfilter,background-colorandclip-pathon the horizon.
How to use Will-change ?
The will-change css property hints to browsers how an element is expected to change. Browsers may set up optimisations before an element is actually changed.
/* Keyword values */
will-change: auto;
will-change: scroll-position;
will-change: contents;
will-change: transform; /* Example of <custom-ident> */
will-change: opacity; /* Example of <custom-ident> */
will-change: left, top; /* Example of two <animatable-feature> */
/* Global values */
will-change: inherit;
will-change: initial;
will-change: revert;
will-change: revert-layer;
will-change: unset;
You can hint to the browser that they should create a new layer by setting the willChange style to "transform":
element.style.willChange = "transform"
Instead of animating boxShadow, animate filter with the drop-shadow function:
// β
#box:hover { boxShadow: "10px 10px black" };
// β
#box:hover { filter: "drop-shadow(10px 10px black)" };
Browser Rendering :
1. Layout (Reflow)
Definition:
The layout phase calculates the position and size of elements in the document based on the CSS and DOM structure.
When It's Triggered:
Adding, removing, or changing the size/position of elements (
width,height,margin,padding, etc.).Resizing the window or changing the font size.
Performance Impact:
Expensive, as it affects the entire document or subtree of elements.
Causes reflow for child elements when dimensions change.
2. Paint (Repaint)
Definition:
The paint phase involves filling in pixels for visual elements, such as colors, borders, text, and shadows.
When It's Triggered:
- Changes to visual properties that donβt affect the layout (
color,background-color,border,box-shadow).
Performance Impact:
- Moderate cost as it redraws only the visual parts of elements but doesn't impact the layout.
3. Composite (Layer Composition)
Definition:
The composite phase involves assembling the different painted layers on the GPU to display the final image on the screen.
When It's Triggered:
- GPU-accelerated properties such as
transform,opacity, andfilter.
Performance Impact:
Least expensive as it avoids recalculating layout or repainting.
Efficiently handled by the GPU for smoother animations.
Summary Table
| Phase | Triggered By | Performance Impact |
|---|---|---|
| Layout | Size and position changes | High |
| Paint | Visual appearance changes | Moderate |
| Composite | GPU-based transforms and effects | Low |
Top comments (0)