{"id":104,"date":"2026-10-18T17:53:12","date_gmt":"2026-10-18T17:53:12","guid":{"rendered":"https:\/\/refracttools.com\/blog\/?p=104"},"modified":"2026-10-18T17:53:12","modified_gmt":"2026-10-18T17:53:12","slug":"scroll-driven-animations-css","status":"publish","type":"post","link":"https:\/\/refracttools.com\/blog\/css-techniques\/scroll-driven-animations-css\/","title":{"rendered":"Scroll-driven animations in CSS with animation-timeline"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Scroll-driven animations link a normal CSS <code>@keyframes<\/code> animation to scrolling instead of time. Set <code>animation-timeline: view()<\/code> to play an animation as an element moves through the viewport, or <code>animation-timeline: scroll()<\/code> to tie it to how far a page or container has scrolled. As of October 2026 they work in Chrome and Edge 115+ and Safari 26+; Firefox is still working on them, so wrap them in <code>@supports<\/code> and treat them as an enhancement.<\/p>\n\n\n\n<div class=\"wp-block-group is-style-refract-takeaways is-layout-constrained wp-block-group-is-layout-constrained\">\n<h3 class=\"wp-block-heading\">Key takeaways<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>view()<\/code> tracks an element crossing the viewport: ideal for fade-in and slide-up reveals.<\/li>\n\n\n<li><code>scroll()<\/code> tracks scroll position: ideal for reading progress bars and parallax.<\/li>\n\n\n<li><code>animation-range<\/code> controls which part of the scroll plays the animation, for example <code>entry 0% cover 35%<\/code>.<\/li>\n\n\n<li>Set <code>animation-timeline<\/code> after the <code>animation<\/code> shorthand, use <code>@supports<\/code>, and respect <code>prefers-reduced-motion<\/code>.<\/li>\n<\/ul>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">What are scroll-driven animations?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">For years, &#8220;animate on scroll&#8221; meant JavaScript: an <code>IntersectionObserver<\/code> or a scroll listener that added classes or set styles as you scrolled. Scroll-driven animations move that job into CSS. You write the keyframes as usual, then swap the timeline. Instead of running over a number of seconds, the animation&#8217;s progress follows the scroll position, so scrolling back up plays it in reverse, and the browser can run it off the main thread for smoother results.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How do you make an element fade in on scroll?<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>@keyframes reveal {\n  from { opacity: 0; translate: 0 40px; }\n  to   { opacity: 1; translate: 0 0; }\n}\n\n@media (prefers-reduced-motion: no-preference) {\n  @supports (animation-timeline: view()) {\n    .reveal {\n      animation: reveal linear both;\n      animation-timeline: view();\n      animation-range: entry 0% cover 35%;\n    }\n  }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Add the <code>reveal<\/code> class to any card, image or heading. Browsers without support, and people who have asked their device for less motion, simply see the content without the effect.<\/p>\n\n\n\n<div class=\"wp-block-group is-style-refract-callout is-layout-constrained wp-block-group-is-layout-constrained\">\n<p class=\"wp-block-paragraph\"><strong>Common mistake:<\/strong> The <code>animation<\/code> shorthand resets <code>animation-timeline<\/code>. If you write <code>animation-timeline<\/code> first and the shorthand after it, the timeline is quietly reset and the animation runs on time instead. Always put the timeline after the shorthand.<\/p>\n<\/div>\n\n\n<aside class=\"tool-card tool-card--inline\"><span class=\"swatch\" style=\"background:linear-gradient(180deg,#2f4bff 0 30%,#9fb0ff 30% 60%,#e6e9ff 60%)\" aria-hidden=\"true\"><\/span><div class=\"tool-card__body\"><p class=\"tool-card__eyebrow\">Free tool<\/p><p class=\"tool-card__name\">Scroll-driven animation generator<\/p><p class=\"tool-card__blurb\">Scroll-triggered reveals and progress bars in pure CSS.<\/p><\/div><a class=\"btn primary\" href=\"https:\/\/refracttools.com\/scroll-animation-generator\/\">Try it free <span aria-hidden=\"true\">\u2192<\/span><\/a><\/aside>\n\n\n\n<h2 class=\"wp-block-heading\">How does animation-range work?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>animation-range<\/code> chooses the slice of the element&#8217;s journey that drives the animation. Each value is a named range plus a percentage:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><div class=\"table-scroll\" tabindex=\"0\" role=\"region\" aria-label=\"Scrollable table\"><table><thead><tr><th>Range<\/th><th>Means<\/th><th>Example use<\/th><\/tr><\/thead><tbody><tr><td><code>entry<\/code><\/td><td>From the element&#8217;s first edge appearing to it being fully inside the viewport<\/td><td>Fade in as it arrives<\/td><\/tr><tr><td><code>exit<\/code><\/td><td>From starting to leave to fully gone<\/td><td>Fade out as it leaves<\/td><\/tr><tr><td><code>contain<\/code><\/td><td>While it is fully inside the viewport (or fully covering it, if taller)<\/td><td>Effects while it is completely on screen<\/td><\/tr><tr><td><code>cover<\/code><\/td><td>From first edge entering to last edge leaving: the whole journey<\/td><td>Parallax, long reveals<\/td><\/tr><tr><td><code>entry-crossing<\/code> \/ <code>exit-crossing<\/code><\/td><td>The element crossing the start or end edge<\/td><td>Fine control on tall elements<\/td><\/tr><\/tbody><\/table><\/div><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><code>entry 0% cover 35%<\/code> starts the moment the top of the element peeks in at the bottom of the screen and finishes when it is a little over a third of the way through. Short ranges feel snappy; long ranges feel more cinematic but can leave content half-faded while people are trying to read it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How do you make a reading progress bar in CSS?<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>.progress {\n  position: fixed;\n  inset: 0 0 auto 0;\n  height: 4px;\n  background: #7b5cff;\n  transform-origin: 0 50%;\n  animation: grow linear both;\n  animation-timeline: scroll(root block);\n}\n\n@keyframes grow {\n  from { transform: scaleX(0); }\n  to   { transform: scaleX(1); }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>scroll(root block)<\/code> follows the whole page&#8217;s vertical scroll. Use <code>scroll(nearest)<\/code> to follow the closest scrolling ancestor instead, such as a scrollable panel. Animating <code>transform<\/code> rather than <code>width<\/code> keeps it smooth, because transforms don&#8217;t trigger layout.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Named timelines<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">When the element that scrolls isn&#8217;t an ancestor of the element you want to animate, give the scroller a name with <code>scroll-timeline-name<\/code> (or <code>view-timeline-name<\/code>) and refer to it from elsewhere with <code>animation-timeline: --name<\/code>. For most reveals and progress bars, the anonymous <code>view()<\/code> and <code>scroll()<\/code> functions are enough.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Which browsers support scroll-driven animations?<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><div class=\"table-scroll\" tabindex=\"0\" role=\"region\" aria-label=\"Scrollable table\"><table><thead><tr><th>Browser<\/th><th>Support (October 2026)<\/th><\/tr><\/thead><tbody><tr><td>Chrome and Edge<\/td><td>115 and later<\/td><\/tr><tr><td>Safari (macOS and iOS)<\/td><td>26 and later<\/td><\/tr><tr><td>Firefox<\/td><td>Not yet by default; available behind a flag<\/td><\/tr><tr><td>Samsung Internet and other Chromium browsers<\/td><td>Yes<\/td><\/tr><\/tbody><\/table><\/div><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Because the <code>@supports<\/code> wrapper hides the effect where it isn&#8217;t available, unsupported browsers show the content normally. Never hide content in a way that depends on the animation running; the starting state should only be applied inside the <code>@supports<\/code> block, as in the examples above.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Do you still need JavaScript for scroll effects?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">For reveals, progress bars and simple parallax, no. CSS now covers them with less code and smoother results. JavaScript is still the right tool when something needs to happen once at a point in the scroll, such as loading more items, sending an analytics event or starting a video, because scroll-driven animations only map scroll position to keyframes. They don&#8217;t fire events. If you need the same reveal in Firefox today, a small <code>IntersectionObserver<\/code> script can add the class as a fallback, but for most sites the plain content is a perfectly good experience.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Accessibility and good taste<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Respect reduced motion.<\/strong> Wrap motion in <code>prefers-reduced-motion: no-preference<\/code>, so people with vestibular disorders aren&#8217;t made unwell.<\/li>\n\n\n<li><strong>Animate opacity and transform.<\/strong> These are cheap for the browser. Avoid animating <code>height<\/code>, <code>top<\/code> or large <code>filter<\/code> blurs.<\/li>\n\n\n<li><strong>Don&#8217;t reveal everything.<\/strong> Animating every paragraph is tiring. Save it for images, cards and section headings.<\/li>\n\n\n<li><strong>Finish early.<\/strong> End reveals well before content reaches the middle of the screen, so it is fully visible by the time someone reads it.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Generate the code<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The <a href=\"https:\/\/refracttools.com\/scroll-animation-generator\/\">Refract scroll-driven animation generator<\/a> gives you fade, slide up, scale, wipe and unblur reveals plus a reading progress bar. You preview each effect by scrolling, set the range, then copy CSS that already includes the <code>@supports<\/code> fallback and reduced-motion check. Its &#8220;Paste into&#8221; menu rewrites the code for Elementor, Divi, Bricks, Breakdance or the block editor. For time-based motion, try the <a href=\"https:\/\/refracttools.com\/css-loader-generator\/\">CSS loader generator<\/a> or the <a href=\"https:\/\/refracttools.com\/button-hover-effects\/\">button hover effects generator<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Last checked: October 2026.<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Sources: <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/CSS_scroll-driven_animations\" rel=\"noopener\" target=\"_blank\">MDN: CSS scroll-driven animations<\/a>, <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/animation-range\" rel=\"noopener\" target=\"_blank\">MDN: animation-range<\/a>, <a href=\"https:\/\/developer.chrome.com\/docs\/css-ui\/scroll-driven-animations\" rel=\"noopener\" target=\"_blank\">Chrome for Developers: scroll-driven animations<\/a>.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Scroll-driven animations link CSS keyframes to scrolling instead of time. Here is how view(), scroll() and animation-range work, with copy-ready reveal and progress bar code and safe fallbacks.<\/p>\n","protected":false},"author":1,"featured_media":103,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_refract_tool":"scroll-animation-generator","footnotes":""},"categories":[8],"tags":[20,52,51],"class_list":["post-104","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-css-techniques","tag-accessibility","tag-animation","tag-scroll-animations"],"_links":{"self":[{"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/posts\/104","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/comments?post=104"}],"version-history":[{"count":1,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/posts\/104\/revisions"}],"predecessor-version":[{"id":109,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/posts\/104\/revisions\/109"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/media\/103"}],"wp:attachment":[{"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/media?parent=104"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/categories?post=104"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/tags?post=104"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}