What is animation-timeline: view()?
Scroll-Driven Animations is a CSS spec that lets you tie a CSS @keyframes animation to the scroll position of an element in the viewport — without any JavaScript. The browser drives it from the scroll position itself; no script runs per frame.
The key property is animation-timeline: view(). Combined with animation-range, you declare “play this animation as the element travels from X to Y in the viewport”. The browser scrubs the animation in sync with scroll — no rAF, no event listeners, no JavaScript execution per frame.
/* Pure CSS scroll-driven animation */
@keyframes draw-path {
from { stroke-dashoffset: var(--path-length); }
to { stroke-dashoffset: 0; }
}
path {
stroke-dasharray: var(--path-length);
stroke-dashoffset: var(--path-length);
animation-name: draw-path;
animation-timing-function: ease-out;
animation-fill-mode: both;
animation-duration: 1s; /* ignored — scroll drives it */
animation-timeline: view(); /* scroll-driven */
animation-range: entry 20% exit 80%;
}The catch: you have to know the path length upfront (to set --path-length), and older browsers — Safari before 26, Firefox before 159 — don't support it. That's where svg-scroll-draw comes in — it measures the length, injects the CSS, and runs the same draw on its JS engine where the browser has no scroll timelines.
How svg-scroll-draw activates the native path
When you call scrollDraw(), the engine first checks whether the config is “native-eligible”. If it is and the browser supports animation-timeline: view(), it generates a <style> tag and injects the CSS keyframe animation — then returns. The JS rAF loop never starts.
If the browser doesn't support it (Safari before 26, Firefox before 159, Chrome before 115), the engine falls back to the full JS path transparently. Your code doesn't change. The animation looks identical.
Native CSS path
- Driven by the browser’s scroll timeline
- Zero per-frame JavaScript
- No scroll event listeners
- No requestAnimationFrame
- Instant response to scroll direction changes
JS fallback path
- IntersectionObserver gating
- requestAnimationFrame loop
- Runs only while visible
- Same visual result
- Full instance API works
- Activates automatically wherever view() is missing
function isNativeEligible(options) {
if (options.native === false) return false; // explicit opt-out
if (!CSS.supports('animation-timeline: view()')) return false;
if (typeof options.easing === 'function') return false; // custom fn = JS
if (!['linear', 'ease-in', 'ease-out', 'ease-in-out'].includes(options.easing))
return false; // spring / bounce / elastic = JS
if (options.stagger !== 0) return false; // stagger needs JS timing
if (options.speed !== 1) return false; // non-1 speed shifts the range
if (options.delay > 0) return false;
if (options.repeat || options.once || options.autoReverse) return false; // loop/once logic = JS
if (options.morphTo || options.waypoints) return false; // path interpolation = JS only
if (options.velocityScale) return false; // needs live velocity
if (options.clip || options.axis !== 'y' || options.scrollContainer) return false;
if (options.onProgress || options.onStart || options.onComplete ||
options.onEnter || options.onLeave ||
options.onEnterBack || options.onLeaveBack) return false; // callbacks need JS frames
if (options.strokeColor || options.strokeWidth || options.fillOpacity) return false;
if (options.trigger.start !== 'top bottom' ||
options.trigger.end !== 'bottom top') return false; // only the default maps to CSS `cover`
return true; // ✓ hand off to CSS
}What triggers native vs JS?
The native path activates when all of these are true:
- Browser supports animation-timeline: view() — Chrome and Edge 115+, Safari 26+, Firefox 159+. Older browsers fall back automatically.
- No callbacks (onProgress, onStart, onComplete, onEnter, onLeave…) — Callbacks require a JS frame to fire. Declaring any callback forces the JS engine.
- No stagger — stagger offsets individual paths by time fractions — CSS can't express per-path delays within a single view() range.
- No morphTo, waypoints, velocityScale, repeat, autoReverse, delay or once — These features need frame-by-frame state management that CSS can't provide.
- Named easing (not a custom function) — linear, ease-in, ease-out and ease-in-out have exact CSS equivalents. Spring/bounce/elastic and custom functions require JS.
- speed === 1 (default) — Non-1 speed values shift the effective trigger range. This is trivial in JS but requires a CSS calc() trick that isn't worth the complexity.
- The default trigger window — Only top bottom → bottom top maps onto the CSS cover range. A custom start or end keeps the JS engine.
- Page scroll on the vertical axis, no clip reveal — The generated view-timeline follows the block axis of the page. scrollContainer, axis: 'x' and clip all stay on JS.
- No animated colors or widths — strokeColor, strokeWidth, fillOpacity — all require per-frame interpolation.
To write the CSS yourself, the CSS scroll-driven animation generator builds animation-timeline rules with a fallback, and the SVG line drawing generator turns any SVG into a file that draws itself with no JavaScript.
Native vs JS — the code is identical
You don't write different code for the native path. The engine decides. Here are examples that hit native, and examples that stay on JS:
Native path activated
import { scrollDraw } from 'svg-scroll-draw';
// Simple logo reveal — native CSS wherever view() is supported
scrollDraw('#logo', {
easing: 'ease-out',
fade: true,
});
// → CSS animation-timeline injected, no JS loopimport { ScrollDraw } from 'svg-scroll-draw/react';
// React component — also hits native path
function Logo() {
return (
<ScrollDraw easing="ease-in-out" fade>
<svg>…</svg>
</ScrollDraw>
);
}
// add once and it moves to the JS path (needs freeze logic)JS path (by necessity)
// onProgress callback → JS path (needs frame-by-frame)
scrollDraw('#chart', {
easing: 'ease-out',
onProgress: (alpha) => {
counter.textContent = Math.round(alpha * 1000);
},
});
// stagger → JS path (per-path offset timing)
scrollDraw('#diagram', {
stagger: 0.15,
easing: 'ease-out',
});
// spring easing → JS path (not a CSS timing function)
scrollDraw('#path', {
easing: 'spring',
});
// custom trigger window → JS path (only the default maps to CSS cover)
scrollDraw('#logo', {
trigger: { start: 'top 80%', end: 'top 20%' },
});
// Opt out explicitly
scrollDraw('#path', {
native: false, // always use JS engine
});Where native runs today
| Browser | Version | Path | Notes |
|---|---|---|---|
| Chrome | 115+ | native CSS | Full support since Jul 2023 |
| Edge | 115+ | native CSS | Same engine as Chrome |
| Safari | 26+ | native CSS | Scroll-driven animations shipped in Safari 26 |
| Firefox | 159+ | native CSS | On by default since 27 Oct 2026 |
| Chrome Android | 115+ | native CSS | Full mobile support |
| Safari iOS | 26+ | native CSS | Same engine as Safari 26 |
| Firefox Android | 159+ | native CSS | Follows desktop Firefox |
| Older versions | — | JS fallback | JS fallback active — same result, no code changes |
What the native path saves
JavaScript animations run on the main thread. When your main thread is busy — parsing JS, running React reconciliation, handling events — the scroll animation stutters. The scroll event fires, the rAF fires, but the frame is delayed. That's why even well-optimised JS scroll animations can drop frames during page load or heavy interaction.
On the native path there is no JavaScript of ours in the frame at all: the browser maps the scroll position to the keyframes itself and redraws the stroke. That is less work than the JS path, and none of it competes with your own scripts. It is not free, though. Browsers composite transform and opacity off the main thread, but stroke-dashoffset is not one of those properties, so each frame still restyles and repaints the path on the main thread — a long task can still delay a frame, with no script of ours adding to it.scrollAnimate's native path for opacity and transform is the one that can run fully on the compositor.
| Scenario | JS | Native CSS |
|---|---|---|
| Heavy page load | The scroll handler and rAF callback queue behind other scripts, so frames run late | No script of ours runs per frame; a long task still delays the next paint |
| React re-renders | Re-renders and the animation callback compete for the same main thread | Nothing of ours competes per frame; only the browser’s own restyle and repaint remain |
| Many animated paths | One rAF loop recomputes every path in JavaScript each frame | The browser animates each path from its keyframes; no JavaScript per path per frame |
Opt-out and instance API
If you need to force the JS engine — for testing, for a polyfill, or because you're debugging — set native: false:
scrollDraw('#logo', {
easing: 'ease-out',
native: false, // always use JS rAF engine
});The full instance API — pause(), resume(), seek(), replay(), destroy() — works on both paths. The native path implements these by toggling animation-play-state and injecting inline offsets.
const instance = scrollDraw('#logo', { easing: 'ease-out' });
instance.pause(); // pauses wherever it is
instance.resume(); // continues from same point
instance.seek(0.5); // jump to 50% drawn
instance.replay(); // restart from 0
instance.destroy(); // remove all styles + observers
instance.getProgress(); // → 0–1TL;DR
- svg-scroll-draw automatically uses the native CSS path on Chrome and Edge 115+, Safari 26+ and Firefox 159+.
- The native path runs zero JavaScript per frame — no scroll listeners, no rAF.
- The JS fallback activates automatically on older browsers — same visual result.
- Any config that needs JS (callbacks, stagger, spring easing, repeat, velocityScale, a custom trigger window) stays on the JS engine.
- The vast majority of real-world logo reveals and path animations hit the native path.
- You don't write different code. The engine decides.
— / next
Try it yourself
Open DevTools → Performance while scrolling a svg-scroll-draw animation. On Chrome, you'll see zero main-thread JS per frame.
Star on GitHubFound this useful? A star helps others find it.