React scroll animations
Use @awesome-reveal/react to add scroll animations to a React app. An element fades and slides in when it scrolls into view. The package does not link an animation to the scroll position, as a parallax effect or a scroll progress bar does.
Install the package
Section titled “Install the package”pnpm add @awesome-reveal/reactFor the supported React versions, see Requirements.
Reveal an element on scroll
Section titled “Reveal an element on scroll”Wrap the element in Reveal:
import { Reveal } from "@awesome-reveal/react";
export function Hero() { return ( <Reveal as="section" from="left"> <h1>Scroll animations in React</h1> <p>The section fades in from the left.</p> </Reveal> );}Reveal renders an element around its children. as sets its tag, and from sets the entrance. To fade, zoom, rotate or blur the element in, set a start state.
Stagger a list with Cascade
Section titled “Stagger a list with Cascade”Cascade reveals its direct children one after the other:
import { Cascade } from "@awesome-reveal/react";
export function Features() { return ( <Cascade as="ul" from={{ opacity: 0, y: 16 }} interval={120}> <li>Fast</li> <li>Small</li> <li>Accessible</li> </Cascade> );}For a long list or a tall grid, see Animate a list.
Reveal your own element with a hook
Section titled “Reveal your own element with a hook”useReveal and useCascade reveal an element that you render, with no wrapper element. Spread the props from getProps() on one DOM element:
import { useReveal } from "@awesome-reveal/react";
export function Card({ title }) { const { getProps } = useReveal({ from: { opacity: 0, scale: 0.95 } });
return <article {...getProps({ className: "card" })}>{title}</article>;}Control the reveal from state
Section titled “Control the reveal from state”To play the entrance when your state changes, such as when a panel opens, give when. To run code when the element reveals, give onReveal.
Server rendering
Section titled “Server rendering”To prevent a flash of the content before hydration, see Server rendering.
- For Next.js, see Next.js scroll animations.
- For a React island in Astro, see React and Vue scroll animations in Astro.
Next steps
Section titled “Next steps”- Use your own keyframes: give native Web Animations keyframes.
- Change the timing: set the duration, the delay and the threshold.
- React API: all the components, hooks and types.