Skip to content

Svelte scroll animations

Use @awesome-reveal/svelte to add scroll animations to a Svelte 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.

Terminal window
pnpm add @awesome-reveal/svelte

The package is a release candidate. For the supported Svelte versions, see Requirements.

Wrap the element in Reveal:

<script>
import { Reveal } from "@awesome-reveal/svelte";
</script>
<Reveal as="section" from="left">
<h1>Scroll animations in Svelte</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.

Cascade reveals its direct children one after the other:

<script>
import { Cascade } from "@awesome-reveal/svelte";
</script>
<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 an attachment

Section titled “Reveal your own element with an attachment”

The reveal and cascade attachments reveal an element that you render, with no wrapper element. Give the options as a function that returns them:

<script>
import { reveal } from "@awesome-reveal/svelte";
</script>
<article
{@attach reveal(() => ({ from: { opacity: 0, scale: 0.95 } }))}
class="card"
>
A card
</article>

For the options function, see Svelte API.

Attachments run only in the browser. For server-rendered content, use Reveal and Cascade. See SvelteKit.

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.

To prevent a flash of the content before hydration, see Server rendering.