One CSS change can run a few stages of the browser rendering pipeline or all of them, and the property and the element’s current state decide which. Knowing which stages run tells you whether the next frame can be ready in time for a 60 Hz or 120 Hz screen. This is the first part of the series “How the browser turns CSS into pixels”.
Four style changes, four Chrome traces
We ran one small page in Chrome and recorded a trace of four different style changes. The page has a 100 by 100 pixel box and one paragraph. After three idle frames, a setTimeout callback makes one change to the box, as a click handler would. Save it as page.html; the ?case= part of the URL picks the change.
<!doctype html>
<meta charset="utf-8">
<title>pipeline test</title>
<style>
body { margin: 0; font: 16px sans-serif; }
#box { width: 100px; height: 100px; background-color: steelblue; margin: 40px; }
.wc #box { will-change: transform; }
.t0 #box { transform: translateX(0); }
</style>
<p>Some text so the page is not empty.</p>
<div id="box"></div>
<script>
const params = new URLSearchParams(location.search);
const kase = params.get('case');
if (kase === 'transform-wc') document.documentElement.className = 'wc';
if (kase === 'transform-from0') document.documentElement.className = 't0';
const box = document.getElementById('box');
const frames = n => new Promise(r => { const f = () => (--n ? requestAnimationFrame(f) : r()); requestAnimationFrame(f); });
const changes = {
'width': () => { box.style.width = '200px'; },
'background': () => { box.style.backgroundColor = 'tomato'; },
'transform-wc': () => { box.style.transform = 'translateX(100px)'; },
'transform-nowc': () => { box.style.transform = 'translateX(100px)'; },
'transform-from0': () => { box.style.transform = 'translateX(100px)'; }, // no will-change, but already had a transform
'forced-layout': () => { box.style.width = '200px'; window.__w = box.offsetWidth; },
};
// Called by the driver once tracing is on. The change runs in its own task (setTimeout),
// like a click handler would, after a few idle frames.
window.run = async () => {
await frames(3);
await new Promise(r => setTimeout(() => {
performance.mark('css-change');
console.timeStamp('css-change');
changes[kase]();
r();
}, 0));
await frames(3);
performance.mark('done');
};
</script>
The four cases in this section are width, background, transform-wc and transform-nowc. The other two come back later. will-change: transform tells the browser ahead of time that the box’s transform will change, and the wc class adds it only in the transform-wc case.
A Node.js script opens the page with puppeteer-core, a Node.js library that controls an installed Chrome. The script starts Chrome’s tracing, calls window.run() and saves the trace as JSON. Install the library with npm install puppeteer-core, and change executablePath to your Chrome:
// excerpt from record.mjs: one run of one case (the full script loops over cases and runs)
import puppeteer from 'puppeteer-core';
import { pathToFileURL } from 'node:url';
const categories = [
'devtools.timeline',
'disabled-by-default-devtools.timeline',
'disabled-by-default-devtools.timeline.frame',
'blink', 'blink.user_timing', 'cc', 'gpu', 'viz', 'benchmark', 'loading', 'toplevel',
];
const pageUrl = pathToFileURL(new URL('./page.html', import.meta.url).pathname).href;
const browser = await puppeteer.launch({
executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
headless: false,
args: ['--window-size=800,600', '--no-first-run', '--no-default-browser-check'],
});
const page = await browser.newPage();
await page.setViewport({ width: 800, height: 600 });
await page.goto(`${pageUrl}?case=width`, { waitUntil: 'load' });
await new Promise(r => setTimeout(r, 500)); // let the page settle
await page.tracing.start({ path: 'width-1.json', categories });
await page.evaluate(() => window.run());
await new Promise(r => setTimeout(r, 200));
await page.tracing.stop();
await browser.close();
A second script, stages.mjs, reads one trace. It finds the css-change timestamp, then lists four kinds of trace event in the change’s own task and in the frame that follows it:
// Usage: node stages.mjs trace.json
import { readFileSync } from 'node:fs';
const STAGES = ['UpdateLayoutTree', 'Layout', 'Paint', 'RasterTask'];
const raw = JSON.parse(readFileSync(process.argv[2], 'utf8'));
const events = (raw.traceEvents || raw).filter(e => e.ph !== 'M').sort((a, b) => a.ts - b.ts);
// The change: the console.timeStamp('css-change') call on the page's main thread.
const mark = events.find(e => e.name === 'TimeStamp' && e.args?.data?.message === 'css-change');
const onMain = e => e.pid === mark.pid && e.tid === mark.tid;
// The task that made the change, and the first main-thread frame after it.
const task = events.find(e => onMain(e) && e.name === 'TimerFire' && e.ts <= mark.ts && e.ts + e.dur >= mark.ts);
const frame = events.find(e => onMain(e) && e.name === 'ProxyMain::BeginMainFrame' && e.ph === 'X' && e.ts > mark.ts);
// That frame is finished when the renderer draws it.
const draw = events.find(e => e.pid === mark.pid && e.name === 'DrawFrame' && e.ts > frame.ts + frame.dur);
const ran = { task: new Set(), frame: new Set() };
for (const e of events) {
if (e.pid !== mark.pid || !STAGES.includes(e.name)) continue;
if (onMain(e) && e.ts >= task.ts && e.ts <= task.ts + task.dur) ran.task.add(e.name);
else if (e.ts >= frame.ts && e.ts <= draw.ts) ran.frame.add(e.name);
}
console.log('in the change task:', [...ran.task].join(', ') || 'none');
console.log('in the next frame: ', STAGES.filter(s => ran.frame.has(s)).join(', '));
The four event names stand for these stages:
- Style (
UpdateLayoutTree): works out the new CSS values of the elements that changed. - Layout (
Layout): works out the size and position of each box. - Paint (
Paint): records drawing commands for the page, such as “fill this rectangle with this color”. - Raster (
RasterTask): raster turns those drawing commands into pixels.
Before you read on, predict which of these four stages each change runs:
widthfrom100pxto200px.background-colorfromsteelbluetotomato.transformtotranslateX(100px), on a box withwill-change: transform.- The same
transformchange, on a box with nowill-changeand notransformbefore it.
This is what stages.mjs prints for the first trace of the width case:
in the change task: none
in the next frame: UpdateLayoutTree, Layout, Paint, RasterTask
We ran each case five times in a Chrome window and five times in headless Chrome, all in Chrome 157 on one Apple M2 Mac with macOS. Each cell below held in all ten runs:
| Change | Style | Layout | Paint | Raster |
|---|---|---|---|---|
1. width |
yes | yes | yes | yes |
2. background-color |
yes | no | yes | yes |
3. transform, with will-change |
yes | no | no | no |
4. transform, from no transform |
yes | yes | yes | yes |
The width change ran every stage. In the trace, layout reported 4 objects needing layout out of the page’s 6. The background-color change skipped only layout, because a new color moves no box, but the pixels under the box still had to be painted and rasterized again.
The transform change with will-change skipped layout, paint and raster. It still ran style on the main thread, because the new value came from JavaScript. The same transform change without will-change ran every stage, as width did, and the next sections explain why.
The trace also records how long each stage took, but on a page this small every stage took tens of microseconds and the numbers changed from run to run. Use these traces to see which stages ran, not what they cost. Your Chrome version, machine and page can give different results, and a page with more layers could change cases 3 and 4.
Rule: The stages a change runs depend on the property and on the element’s state before the change, not on the property alone.
When the browser runs the rendering work
In every case, the setTimeout task did no rendering work. It only recorded that style needed recalculating, as a ScheduleStyleRecalculation event. Style, layout and paint ran in the next frame, 14 to 17 ms later, which is the wait for the next refresh of a 60 Hz screen.
The HTML standard describes that wait (HTML Standard, “update the rendering”). The browser waits for a rendering opportunity, a moment when it can update the screen. The spec ties rendering opportunities to the display’s refresh rate, to page performance and to whether the page is visible. At 60 Hz, its example is a rendering opportunity about every 16.7 ms.
At each rendering opportunity the browser queues a task to update the rendering, the task that brings the screen up to date with the DOM and CSS. Inside it, the order is fixed by the spec:
- Update animations and send their events, for CSS animations, CSS transitions and Web Animations.
- Run
requestAnimationFramecallbacks. - Recalculate styles and update layout, again if a
ResizeObservercallback changes layout. - Run
IntersectionObserverwork. - Update the rendering of the document “to reflect the current state”.
So CSS animations move before your requestAnimationFrame callbacks run, and style and layout run after them. Both get the same frame timestamp. The spec does not define what step 5 does, so paint, raster and drawing are each browser’s own design. The rest of this article follows Chromium, the open-source project behind Chrome, and a note at the end of the pipeline sections covers Firefox and Safari.
Chrome skips the main-thread part of a frame when nothing on the main thread changed (Life of a frame). A requestAnimationFrame callback or a changed style asks for one (How cc works).
Rule: A style write marks work as needed, and the next rendering opportunity does it, unless your JavaScript reads layout first.
The browser rendering pipeline in Chromium, stage by stage
Chromium’s RenderingNG documentation lists twelve stages (RenderingNG architecture). Eight of them decide what a style change costs: the four from the trace, and four more that ran in every case. The other four (animate, scroll, activate and aggregate) handle animations, scrolling and the last steps before drawing, and this article leaves them out.
| Stage | What it does |
|---|---|
| Style | Works out the new CSS values of the elements that changed. |
| Layout | Works out the size and position of each box. |
| Pre-paint | Works out the transform, clip and effect data that painting needs, and marks old paint output as out of date. |
| Paint | Records drawing commands. |
| Layerize | Groups the drawing commands into layers that can be rastered and moved separately. |
| Commit | Copies the main thread’s results to a second thread, the compositor thread. |
| Raster | Turns drawing commands into pixels, in tiles of GPU memory. |
| Draw | Puts the tiles together into one frame and draws it on the GPU. |
Add 'PrePaint', 'Layerize', 'Commit' to the STAGES list in stages.mjs, and those three appear in every case, including case 3.
Which thread runs each stage
The main thread runs your JavaScript, event handlers, HTML parsing and the stages from style to commit. The compositor thread is a second thread in the same renderer process, and it handles input, scrolling and animations and schedules raster work. Viz is one process for all of Chrome, and its GPU thread rasters tiles and draws frames (RenderingNG architecture).
Main thread Style → Layout → Pre-paint → Paint → Layerize → Commit
│
Compositor thread schedules raster work ▼
Worker threads, GPU Raster
│
Viz process ▼
Draw
The 2021 architecture diagram puts layerize on the compositor thread. The BlinkNG article from 2022 says that diagram is “a bit ahead” of the code, and layerize still runs on the main thread (BlinkNG). Blink, the rendering engine inside Chrome, still holds the layerize code today (Blink paint README). In our traces, Layerize also ran on the main thread in every run.
Raster in our traces ran on a thread-pool worker, and DevTools shows those under “Thread pool”. Draw ran last in every case, so every change produced a new frame on screen.
How Chrome decides which stages to run again
Each stage keeps its last output and redoes only the parts marked as out of date. Marking those parts is invalidation, and a part that is marked is dirty.
For style, Blink compiles your style rules into sets keyed by id, class, tag and attribute name. A DOM change marks only the elements those sets could match (style invalidation in Blink). Adding class c1 with the rule .c1 div.c2 marks only the div.c2 elements inside it. The sets err toward marking too much, never too little.
After style, Blink compares each changed element’s old and new computed style in ComputedStyle::VisualInvalidationDiff (computed_style.cc). The result says whether the element needs layout, what kind of paint invalidation it needs, and whether its transform or opacity changed. Each CSS property declares which of these it can cause in css_properties.json5. width declares layout, background-color declares a background-color change, and transform declares only transform changes.
Layout keeps its output and the input constraints of each box, and lays out a child again only when its constraints changed (LayoutNG). In practice it usually rebuilds only the path from the changed box up to the root. Style and layout flag the objects that may need repainting, pre-paint checks those flags, and paint reuses the cached drawing commands of every other object (Blink paint README). Raster redraws only the tiles whose content changed.
Rule: A change runs a stage only when it leaves something in that stage dirty.
Property trees, and why a transform can skip paint
Pre-paint builds four property trees for the document: transform (which also holds scroll offsets), clip, effect (opacity, filters, masks, blend modes and clip-path) and scroll (RenderingNG data structures). Paint groups drawing commands into chunks, and tags each chunk with its node in each tree. The drawing commands of a moved box stay the same, and only its transform node changes.
For transform and opacity, Blink can update the node in the property tree directly, without the walk over the layout tree that rebuilding the trees needs (Blink paint README). That is case 3, with no layout and no paint. The code allows this only when the node already exists (paint_property_tree_builder.cc).
Layerize then decides which chunks get their own composited layer, a surface that is rastered on its own and that the compositor can move. It merges chunks by default, and keeps a chunk apart when its transform is expected to change on the compositor thread (RenderingNG data structures). will-change: transform is one reason to keep it apart. When a composited layer moves, no raster is needed.
To check this, we traced one more case, transform-from0. The box already had transform: translateX(0) and no will-change, then got the same change. It ran no layout and no paint, but raster ran in all ten runs. The box shared the page’s layer, and Chromium’s raster invalidator marks the tiles under the chunk’s old and new position for raster again.
Case 4 started from no transform at all, so the box had no transform node. Gaining a transform also made it a stacking context. When a change flips whether an element is a stacking context, VisualInvalidationDiff asks for full layout and paint (computed_style.cc). The same flip happens when opacity goes from 1 to below 1, or z-index from auto to a number.
will-change: transform does not take a transform you set from JavaScript off the main thread. In case 3, style, pre-paint, layerize and commit ran on the main thread in every run. Only a running CSS animation, CSS transition or Web Animation lets the compositor thread change the transform node by itself, with no main-thread step (RenderingNG architecture, How cc works). Our traces did not cover that case.
Rule: A transform or opacity change skips layout and paint only when the element already has that property-tree node. It skips raster only when the node has a composited layer.
Firefox and Safari: The other engines do the same jobs in the same order, under other names. Firefox calls layout “reflow” (web.dev). Firefox’s rendering overview describes a display list built in the content process and sent to WebRender, its renderer in the GPU process. There, a spatial tree for transforms and scrolling does the job of Chromium’s transform tree (Firefox rendering overview).
WebKit, the engine in Safari, decides which elements get their own layer before painting, from its tree of RenderLayers. On Apple platforms each such layer is backed by a Core Animation layer (WebKit wiki, WebKit commit, 2018). Chromium has layerized after paint since its Composite After Paint project finished shipping in 2021 (RenderingNG).
The frame budget at 60, 90 and 120 Hz
A frame has to be ready before the screen’s next refresh. At 60 Hz that is 1000 / 60 = 16.7 ms, at 90 Hz 11.1 ms, and at 120 Hz 8.3 ms. requestAnimationFrame generally runs at the display’s refresh rate, and MDN names 75, 120 and 144 Hz as widely used besides 60 Hz (MDN).
The frame budget is the time between two refreshes, shared by your JavaScript and every stage your change reaches. Google’s RAIL model says to produce each animation frame in 10 ms or less, because the browser needs about 6 ms of the 16 ms (RAIL). That page was last updated in June 2020 and does the arithmetic for 60 Hz only. At 120 Hz the whole frame is 8.3 ms, so treat 10 ms as a 60 Hz rule of thumb, not a budget for every screen.
Forced synchronous layout and layout thrashing
The sixth case in the test page, forced-layout, sets the width and then reads it back in the same task:
// excerpt from page.html: the forced-layout case
box.style.width = '200px';
window.__w = box.offsetWidth;
Predict where style and layout run this time. Run stages.mjs on that trace:
in the change task: UpdateLayoutTree, Layout
in the next frame: Paint, RasterTask
offsetWidth needs the new width now, so Chrome ran style and layout inside the JavaScript task. The next frame had no style or layout left to do. This is forced synchronous layout, where a read that needs layout makes the browser lay out the page at once, inside your task.
Done once, it moves work earlier. Done in a loop of write, read, write, read, it lays out again on every read, which is called layout thrashing (web.dev).
In Chromium’s element.cc, each of these updates style and layout before it returns:
offsetLeft,offsetTop,offsetWidth,offsetHeightandoffsetParentclientLeft,clientTop,clientWidthandclientHeightscrollLeftandscrollTop, both reading and setting themscrollWidthandscrollHeightscrollBy(),scrollTo()andscrollIntoView()getClientRects()andgetBoundingClientRect()
The update covers the whole document, not only the element you read (document.cc). Layout caching keeps the work in proportion to what changed, but every pending change in the document is laid out. getComputedStyle() forces layout only when you read a property that depends on layout, such as a resolved width (css_computed_style_declaration.cc).
Your JavaScript runs on the same main thread, so its time comes out of the same frame budget. Chrome runs it with V8, the same engine as Node.js, and How V8 runs your JavaScript inside Node.js explains how V8 compiles and runs it. To avoid thrashing, read every value you need first and write afterward. The cost is code structure, because a component that measures itself and then resizes itself has to be split into a read phase and a write phase.
Layers cost GPU memory
A composited layer saves raster when it moves, but each one holds its own tiles in GPU memory. Chromium’s docs say that one layer per paint chunk “would quickly exhaust GPU memory”, which is why layerize merges by default (RenderingNG data structures).
will-change asks for that layer before anything changes. MDN calls it a last resort, and says overuse causes excessive memory use (MDN). It also creates a stacking context up front, and a value set in a stylesheet keeps the optimization longer than one toggled from script. A property that is being animated already gets the same treatment without it.
In case 3, the box had its layer before tracing started. The cost of creating that layer is not in our results.
Dropped and partially presented frames
When main-thread work misses the deadline, Chrome does not wait for it. It sends the frame with the last finished state, without the update, which is one way a frame is dropped (Life of a frame). Raster works the same way, so tiles that are not ready by the deadline are drawn from what Chrome already has.
The DevTools Performance panel marks each frame as one of these (Performance features reference):
- Frame (green): the frame arrived in time.
- Partially presented (yellow): some updates arrived in time, such as compositor scrolling, while main-thread work was late.
- Dropped (red): Chrome could not render the frame in time.
DevTools added the partially presented category in Chrome 100. Before that, any frame with late main-thread work showed as dropped, even when a scroll on the compositor thread reached the screen (What’s new in DevTools 100). So a compositor animation can keep moving while the main thread is late, and a JavaScript-driven one cannot.
Which stages each CSS property reaches in Chrome
This table follows Chromium’s source as of November 18, 2026, roughly Chrome 160 code (css_properties.json5, computed_style.cc, compositor_animations.cc). Our traces in Chrome 157 match its rows for width, background-color and transform. Each row is a one-off change to an element that is already on screen.
| First dirty stage | Stages that run | Changes |
|---|---|---|
| Layout | Style, Layout, Pre-paint, Paint, Layerize, Commit, Raster, Draw | width, height, margin, padding, display, position, contain, content-visibility; font-size, font-weight, letter-spacing (the text is shaped again first); top, left, right, bottom on a positioned element (a cheaper, positioned layout); any change that flips a stacking context |
| Paint | Style, Pre-paint, Paint, Layerize, Commit, Raster, Draw | color (only on elements that paint text or currentColor), background-color, box-shadow, border-radius, outline-color, outline-width, visibility (except to or from collapse), clip-path, z-index on an element that is already a stacking context (its parent stacking context is repainted) |
| Pre-paint | Style, Pre-paint, Layerize, Commit, Raster only without a composited layer, Draw | transform, translate, rotate, scale, opacity changes that stay above 0 and below 1, filter, backdrop-filter, when the element already has the matching property-tree node |
| None on the main thread | Raster for background-color and clip-path only, Draw |
A running CSS animation, CSS transition or Web Animation of transform, translate, rotate, scale, opacity, filter (not pixel-moving filters such as blur()), backdrop-filter, background-color or clip-path |
Two caveats change which row a change lands in:
- Stacking-context flip: some changes make the element a stacking context, such as
opacityfrom 1 to below 1,transformfromnoneorz-indexfromautoto a number. So doposition: fixed,filterorbackdrop-filterfromnone, andwill-change: transformorwill-change: opacity. Each of these runs the Layout row once, and later changes of the same property follow their own row. - Existing layer: the Pre-paint row skips raster only when the element has a composited layer, from
will-change, a 3D transform or a running compositor animation. Otherwise its tiles in the shared layer are rastered again, as intransform-from0.
So “composite-only properties” describes a property in a given state, not the property alone. A compositor animation also needs one main-thread frame to start, change or cancel it (Blink animation README).
Firefox and Safari: The properties that can animate on the compositor differ. Firefox can run
opacity,transform,translate,rotate,scale,background-color(not on thehtmlorbodyelement) and theoffset-*motion path properties there, with nofilter,backdrop-filterorclip-path(longhands.toml). WebKit acceleratesopacity,filter,backdrop-filter,transform,translate,rotateandscale, and the motion path properties when threaded animations are on, with nobackground-colororclip-path(CSSProperties.json). Both were read on their main branches on November 18, 2026.
Why csstriggers.com no longer matches Chrome
Paul Lewis published CSS Triggers in 2014 with data for Blink only (CSS-Tricks). In February 2016 he and Surma relaunched it with data for Blink, Gecko, WebKit and EdgeHTML (GoogleChromeLabs/css-triggers). The repository does not record which browser versions were measured. Its data last changed in June 2017, and the repository was archived in September 2022.
The domain expired in August 2022 (issue #60). The site at csstriggers.com today is a different one, with different data, so cite the repository instead.
Chromium’s layout and paint were rebuilt after 2017, with LayoutNG and Composite After Paint finishing in 2021 (RenderingNG). In the old Blink data, box-shadow, outline-color and visibility triggered layout. In current Chromium source they skip layout, except a change to or from visibility: collapse (css_properties.json5). The old data marked transform and opacity as composite only, and it had no separate rows for a value set from JavaScript and a running animation.
What changed in Chrome since 2021
- Composited SVG animations and percentage transforms (2021): Chromium 89 runs these on the compositor (Chrome blog). That February 2021 post also said
background-colorandclip-pathwould follow “soon”. - Composited
background-colorandclip-pathanimations (2025, 2026): Chromium turned them on by default in the Chrome 142 source forbackground-colorand Chrome 152 forclip-path(issue 40136489, issue 40503852). A native paint worklet is Chrome’s built-in painter for these animations, and it rasters the new background or clip on the compositor side every frame. Main-thread paint is skipped, but raster still runs. - Long Animation Frames API (2024): Chrome 123 shipped it (Long Animation Frames API). A long animation frame is a rendering update delayed beyond 50 ms. Its script entries include
forcedStyleAndLayoutDuration, which shows forced layout on real users’ devices. The cost is that it reports only frames over 50 ms, so a short forced layout does not show. - INP becomes a Core Web Vital (March 2024): Interaction to Next Paint replaced First Input Delay on March 12, 2024. “Good” means 75% of interactions under 200 ms (web.dev). Its last phase is the delay until the next frame is presented, so the stages in this article count toward it.
- Commit without blocking the main thread (2022 prototype): Chromium’s docs say commit blocks the main thread while it copies (How cc works). The BlinkNG article announced a non-blocking commit as a prototype in 2022. In current source, the main thread waits for commit only when the next frame shows the response to an input event. It also waits when it needs data the commit is using (
proxy_main.cc).
How to read a frame in the DevTools Performance panel
You can repeat the trace on your own page without a script:
- Add
performance.mark('css-change')to the handler that makes the change. - Open DevTools, then the Performance panel. Click Record, trigger the change once, and click Stop.
- Find
css-changeon the Timings track. - On the Main track, move to the next frame. The Frames track shows where frames start and end.
- Open the Thread pool track, or the Raster track, to find raster work.
- Click a Recalculate style or Layout event to see the style or layout invalidation that caused it.
The DevTools source uses these labels for the eight stages (devtools-frontend):
| Stage | DevTools label | Track |
|---|---|---|
| Style | Recalculate style | Main |
| Layout | Layout | Main |
| Pre-paint | Pre-paint | Main |
| Paint | Paint | Main |
| Layerize | Layerize | Main |
| Commit | Commit | Main |
| Raster | Rasterize paint | Thread pool or Raster |
| Draw | Draw frame | Frames |
Pre-paint, Layerize and Commit appeared in our traces even in idle frames where nothing changed, so they do not prove that your change reached them. The four that told our cases apart are Recalculate style, Layout, Paint and Rasterize paint. If Recalculate style and Layout appear inside your handler’s task instead of the next frame, that is a forced layout. DevTools shows a forced reflow warning on it (DevTools performance tutorial).
This has two limits. The labels come from the DevTools source code, so your Chrome version may word them slightly differently. And on a small page each stage takes microseconds, so a trace shows which stages ran, not what they cost on a large page.
Animate transform and opacity with CSS or Web Animations
To move a box over time, let the compositor run the animation with a CSS transition, a CSS animation or the Web Animations API:
const box = document.querySelector('#box');
box.animate(
[{ transform: 'translateX(0)' }, { transform: 'translateX(100px)' }],
{ duration: 300, easing: 'ease-out' },
);
Changing box.style.transform in a requestAnimationFrame loop runs style, pre-paint, layerize and commit on the main thread every frame, as case 3 did once. If the main thread is busy with other JavaScript, those frames are late.
A compositor animation still needs a main-thread frame to start, change or cancel it. An animated element is also treated as if it had will-change, with the layer memory that brings (MDN). Chrome falls back to the main thread for pixel-moving filters such as blur(), and for elements split across columns (compositor_animations.cc). Our traces did not test a compositor animation, so check this one in DevTools before you rely on it.
Give an element its transform before you animate it
Case 4 ran layout and paint because its first transform flipped the box into a stacking context. Set the starting value in CSS, and the first change follows the Pre-paint row instead:
.card {
transform: translateX(0);
}
That is the transform-from0 case, which ran no layout and no paint. Raster still ran because the box had no composited layer. Add will-change: transform only if Rasterize paint shows up as a real cost in DevTools.
The cost is that the element is always a stacking context, so the z-index values of its children no longer stack against the rest of the page. will-change adds a composited layer, and every layer holds GPU memory for as long as it exists.
Next, record one interaction on a page you work on, and check which of Recalculate style, Layout, Paint and Rasterize paint ran in the frame after it.
Further reading:
- The HTML Standard’s update the rendering steps
- RenderingNG architecture, RenderingNG data structures, BlinkNG and LayoutNG
- Chromium’s How cc works and Life of a frame
- Blink’s paint README and style invalidation docs
css_properties.json5andComputedStyle::VisualInvalidationDiffincomputed_style.cc- The Long Animation Frames API and the DevTools Performance features reference
If you want the next part of this series when it comes out, subscribe to the newsletter.
Comments
No comments yet. Ask a question or share what worked for you.