Performance · JavaScript and CSS
Excessive main-thread work
A CSS animation on this page changes the width of a block of 400 cells, so the browser recalculates styles and layout on every frame.
How this page is built
The page has a hidden block of 400 cells, each with a line of text added by CSS. A four-second CSS animation widens the block, so the text in every cell wraps again on every frame and the browser has to recalculate styles and layout each time. No JavaScript is involved.
The block is one pixel high and hidden, so the animation cannot be seen and does not move anything else on the page.
Why it matters
The main thread runs JavaScript, works out styles and layout, and paints the page. While it is busy it cannot respond to taps, clicks or key presses. Main-thread work is not only JavaScript: animating properties such as width, height or margin makes the browser redo layout on every frame.
Lighthouse slows the processor down by four times to imitate a mid-range phone, so work that is quick on a laptop can add up to seconds.
How to check it
Run Lighthouse or PageSpeed Insights on the page and look at the diagnostics. Crawl tools that run Lighthouse for each page, or that measure page resources, report the same finding across the site. Lighthouse breaks the main-thread time down into script evaluation, style and layout, rendering, parsing and other work. The Performance panel in Chrome’s developer tools shows when each piece happened.
How to fix it
Animate only translate, scale, rotate and opacity, which the browser can hand to the compositor without new layout. Reduce the number of elements that change at once, simplify styles, and break up long scripts.