The opposite day on the CSS-Tips Slack channel, Danny Schwartz shared an fascinating latest Grasp.dev article by Ashutosh Biswas on how you can stagger CSS scrolling animations utilizing a intelligent combo of a number of emergent CSS options and numerous math, which Ashutosh admits is “an enormous method and might look intimidating.”
I’ll agree with Ashutosh there.
A heartbreaking work of staggering genius
When Danny Slacked the hyperlink for the Frontend Masters article, he described it as “CSS on medication.” Talking of medication, I’m on heavy prescription painkillers whereas recovering from a severe damage, so which may not assist my present comprehension expertise. Nonetheless, after studying Ashutosh’s article just a few instances, right here’s a meme displaying how I’d really feel utilizing such an elaborate algorithm for one thing as mundane as staggering the animations of some characters as they scroll into view.

Don’t get me fallacious. I do know the complexity is as a result of Ashutosh goes for a generic resolution by which we are able to join a “progress worth to an animation, scroll progress, or some other enter to drive the staggering.”
In actual fact, I can dream up a state of affairs by which this may be what we would like: Think about a CSS karaoke machine that shows a ball bouncing on textual content that incrementally highlights, primarily based on the consumer’s progress via the vocals measured by way of speech recognition. Operating that type of animation “not as a set of independently timed objects, however as a single predictable, holistic impact pushed by one progress worth” may be precisely what the physician ordered. This could be true as a result of the staggered animations could possibly be interrelated, and the general animation could be pushed by a customized enter that’s not constructed into the browser.
However in contrast to this hypothetical state of affairs, changing the passage of time with scroll progress to regulate animations is already constructed into fashionable CSS. I contend that we’d want a greater cause to roll our personal implementation than the examples Ashutosh provides.
Ashutosh showcases a scroll-driven use case as “a kind of perfect situations the place the stagger method shines.” However a purple flag that we’re in peril of reinventing one thing we are able to get at no cost is that the spec for scroll-driven animations is cognizant that if we choose to base an animation on scroll progress somewhat than on time, then, as Ashutosh says, “the animation we’re going to obtain is completely different from conventional ones as a result of we don’t embody time in our concerns.” That is no shock to the creators of scroll timeline, and the MDN docs make Ashutosh’s level in numerous phrases when introducing scroll timeline.
The docs additionally level out that animation-delay is solely significant once we are utilizing the default time-based doc timeline. Due to this fact, animation-delay doesn’t have an effect on scroll-driven animations. However this is the reason CSS launched animation-range-start, which permits us to delay a scroll-driven animation relative to scroll progress and never time.
So, as esoteric and trippy because the math-heavy strategy seems, that could possibly be as a result of we’re doing one thing that must be easy in an uncommon approach.
Let’s see if I’m proper by rewriting Ashutosh’s demo to take away reliance on customized CSS capabilities and use animation-range-start as a substitute.
Rewriting a rewrite
Ashutosh’s rework of Frontend Masters’ animated tally of donations within the web site footer is a nifty, refined use of scrollytelling that makes the consumer really feel invested in revealing that quantity.
Sidenote: The one qualm I’ve about this use of scroll-driven animations for the donation tally is that it may be too refined — if the consumer scrolls too rapidly, the animated entrance of every digit may happen too rapidly to note. Due to this fact, the donation tally could possibly be a superb case research for evaluating the deserves of scroll-driven versus scroll-triggered animations as design choices. Nevertheless, that story must wait for an additional day, as the main focus of this text is just to indicate that the staggered scrolling CSS animations may be enormously simplified.
Within the video beneath, my eight-year-old narrates, as a reminder that simplicity is vital to the net we’re selecting to go away to the subsequent technology. He compares the complicated math within the authentic demo supply code with my animation-range-start fork. He exhibits the 2 variations working facet by facet, demonstrating that generally the one factor we lose by judiciously deleting complicated code is a headache.
And for these utilizing a Chromium-based browser, my fork of the Pen is beneath. You may peruse the CSS to see the way it does away with the grand unified principle of staggered scrolling animations, and as a substitute offers solely with the issue at hand. Since I preserved the unique performance, you’ll have to scroll steadily to understand the staggered animations.
A simplistic staggering method for math phobics
I as soon as tackled a associated drawback with a mathematical method in a earlier article, which touched on how we are able to use sibling-index() to “increment animation-range-start to stagger the delay earlier than characters fade in because the consumer scrolls.”
The reality is, if we refuse to fall into the coding entice of probably abstracting the fallacious factor, we are able to use one line of CSS to interchange a method that took 1.3k phrases within the Frontend Masters article for me to nonetheless not absolutely grasp:
animation-range-start: include calc(10% + 2.5% * sibling-index());
The two.5% increment for every sibling is as a result of there are eight characters to stagger, and I wished to choreograph the animations such that they’re delayed in evenly-spaced increments until the final character makes its animated entrance when it reaches 30% of the containment vary (10% + 20%).
Avoiding reinventing easing capabilities
It was inadvertently apt to explain the unique submit as “CSS on medication.” When you reinvent one built-in CSS function, you may’t cease there. You end up having to recreate extra stuff that CSS ought to be capable to do by itself. Positive sufficient, even after we get via the customized formulation that make scroll timelines do what they already do, Ashutosh publicizes, “Sadly, we are able to’t use easing key phrases or cubic-bezier() or linear() capabilities right here. We’re left on our personal to create easing capabilities.”
We shouldn’t should as a result of, regardless of the phrase “timing” within the title of the animation-timing-function property, MDN is evident that “animation-timing-function has the identical impact when creating CSS scroll-driven animations because it does for normal time-based animations.” I do know from expertise that scroll-driven animations work with animation-timing-function as a result of I used scroll-driven animations with steps() to animate a sprite climbing a ladder in my CSS scrollytelling recreation.
The issue within the land of CSS on medication is that after merging all of the staggered animations into one, the easing applies to the whole grasp timeline somewhat than to every factor. It’s not a flaw in CSS, however a logical consequence of the “holistic impact pushed by one progress worth.” Watch out what you want for.
In protection of reinventing the wheel
To be truthful, over time I’ve seen spectacular outcomes from builders reinventing issues the browsers already do, often as a result of the reinvention provides us management we couldn’t get hold of in any other case.
| Mission | Browser functionality being reinvented | What we gained | What it price |
|---|---|---|---|
| React | DOM updates and UI reconciliation | Declarative UI, element mannequin, state-driven rendering, cross-platform renderer structure | Further abstraction layer, bundle dimension, digital DOM overhead, tougher debugging of precise DOM |
| Pretext | Browser textual content measurement and line breaking | Textual content format with out touching DOM, predictable measurements, virtualized lists, server-side potentialities, excessive efficiency for bulk calculations | Should sustain with browser typography conduct, additional upkeep burden, duplicate format engine logic |
| CSSTree | Browser CSS parsing | Programmatic evaluation, transformations, linting, optimization, AST entry | Sustaining compatibility with evolving CSS specs, parser complexity |
I point out this to indicate that reinventing one thing like scroll timelines isn’t an inherently dangerous concept if we all know why we’re doing it. In spite of everything, scroll timelines are solely a reinvention of what builders have been doing for many years prior in JavaScript. Having stated that, I imagine my rewrite of the staggered scroll-driven tally demo exhibits that the unique strategy was overkill for that instance. Do let me know within the feedback in case you see any benefit to the customized CSS capabilities model over utilizing animation-range-start.
Wrapping up
And but the thought that caught with me in regards to the Frontend Masters submit is that it opens the door to linking the progress of a CSS animation to any arbitrary enter worth that could possibly be utilized in a conceptually related strategy to scroll timelines.
This actually appeals to me, as a result of even once I first began writing about scroll timelines in 2024, I talked about that “I’d like to see different enter controls that may manipulate animation timelines. Think about textual content fields progressing animations as you fill them out.” Or how about an animation pushed by how carefully the brand new password you’re typing matches a password scheme?
Sidenote: Adam Argyle’s Prop For That library, which Geoff not too long ago wrote up, makes it extra handy than ever to expose validation details about a area by way of CSS customized properties.
I can add my hypothetical karaoke machine state of affairs to the wishlist of customized progress inputs for controlling animations. How about an animation pushed by the consumer’s progress via a quiz or a procuring cart?
Customized animation timelines would open the door to all types of partaking consumer experiences—however the code Ashutosh has shared often is the closest we’re more likely to get to driving CSS animations utilizing values aside from time or scroll progress.
Let me know within the feedback in case you can consider different forms of progress inputs that might drive CSS animations to create immersive, interactive experiences.
Writer Interview
CSS-Tips editor Geoff Graham sits down with creator Lee Meyer to demo Google’s Immediate API and weigh it (good and dangerous) place in front-end improvement.






