also called custom property invalidation · style recalc scope
Where the angle is declared decides what it costs. On the root, every element on the page re-resolves its colours each frame; on the stage, only the stage does. Scope is the whole difference between a palette that animates for free and one that eats the frame budget. Measured here in Chrome, frame to frame: declared on the swatches, the turn leaves the page at the screen’s own pace; declared on the root, it drops to about a fifth of that, for a change that still shows only on the same 24 swatches. An inherited custom property that changes on an element changes on everything below it, used or not, and every one of those elements is given a fresh computed style each frame: the recalculation and the garbage it leaves are the whole cost, and a trace shows the painting of it almost free. Asked of the painting, all 3,456 dots take the angle, and the cost buys something. The counter caught a selector as well: with a :has() in the dots’ rules their style work was five times greater, every element re-matching its selectors each frame, so the choice is mirrored into an attribute. Declare an animated property as low in the tree as it will serve, and register it with inherits: false when one element is all that needs it.
How it is built
@property --turn { syntax: '<number>'; inherits: true; initial-value: 0 } /* degrees */
.swatches li { background: oklch(from var(--c) l c calc(h + var(--turn))) }
.swatches { animation: turn 8s linear infinite } /* 25 elements re-resolve each frame */
:root { animation: turn 8s linear infinite } /* all of them do, though only 24 use it */In full, on GitHub index.html showcase.css showcase.js
Painting — Georges Seurat, A Sunday on La Grande Jatte — 1884, 1884–86, Art Institute of Chicago, public domain, via Wikimedia Commons; its dots sampled from the image in the browser, its swatches its 24 most representative colours. Facts — A Sunday Afternoon on the Island of La Grande Jatte; @property (MDN).