Scroll-driven Animations for Tailwind CSS

Unofficial and experimental plugin that provides utilities for scroll-driven animations in Tailwind CSS v4+. An earlier release of the plugin supports Tailwind CSS v3.4+.

Installation

Tailwind CSS v4

Install the plugin from npm.

npm install @adam.plesnik/tailwindcss-scroll-driven-animations

Then register the plugin in your main CSS file.

@import 'tailwindcss'; @plugin '@adam.plesnik/tailwindcss-scroll-driven-animations';

Tailwind CSS v3

Install the v0.3 release of the plugin, which supports Tailwind CSS v3.4+.

npm install @adam.plesnik/tailwindcss-scroll-driven-animations@0.3

Then add the plugin to your tailwind.config.js.

module.exports = { plugins: [ require('@adam.plesnik/tailwindcss-scroll-driven-animations'), // ... ], }

How to Make Your CSS Animation Scroll-driven

CSS animations consist of two components, a set of keyframes and a style describing the animation. Let's declare a simple translate-down keyframe set and apply it to an element we want to control by a scroll timeline.

@keyframes translate-down { to { translate: 0; } }
<div class="animate-translate-down timeline"> <!-- The animation should be controlled by the timeline. --> </div>

To effectively control the animation, make sure to declare the timeline in the code after the animation. By default, the shorthand animation property sets the animation-timeline: auto unless set otherwise. However, using this plugin and Tailwind CSS animations ensures that the declaration order is correct.

.timeline { /* This timeline would be overriden */ animation-timeline: scroll(y); } .animate-translate-down { animation: translate-down 3s cubic-bezier(0.65, 0.05, 0.17, 0.99) forwards; } .timeline { /* This is the correct order */ animation-timeline: scroll(y); }

Scroll the container.

timeline before animate-translate-down
animate-translate-down before timeline
Created by Adam Plesník, Bratislava, Slovakia