typography

Split Reveal

A text animation component that masks content and reveals lines, words, or characters upon mounting.


Installation

Install the component

Run the following command to install the component and its dependencies:
npx @motion-core/cli add split-reveal

Import the component

Import the component into your Svelte file:
import { SplitReveal } from "$lib/motion-core";
import { SplitReveal } from "$lib/motion-core";

Usage

We’re using GSAP’s SplitText to break this content into lines, words, and individual characters. Experiment with staggered tweens, custom ease functions, and dynamic transforms to bring your headlines to life.
<script lang="ts">
	import { SplitReveal } from "motion-core";
	import { cn } from "$lib/utils/cn";

	type SplitMode = "lines" | "words" | "chars";

	const modes: SplitMode[] = ["lines", "words", "chars"];
	let activeMode: SplitMode = $state("lines");
	let replayKey = $state(0);

	const handleModeChange = (value: SplitMode) => {
		activeMode = value;
		replayKey += 1;
	};
</script>

{#key `${activeMode}-${replayKey}`}
	<SplitReveal
		mode={activeMode}
		class="absolute top-1/2 left-1/2 block w-sm -translate-x-1/2 -translate-y-1/2 p-8 text-center text-lg md:w-3xl"
	>
		We’re using GSAP’s SplitText to break this content into lines, words, and
		individual characters. Experiment with staggered tweens, custom ease
		functions, and dynamic transforms to bring your headlines to life.
	</SplitReveal>
{/key}
<div
	class="absolute bottom-4 left-1/2 flex w-fit -translate-x-1/2 justify-center gap-1 rounded-lg border border-border bg-background p-1 shadow-sm"
>
	{#each modes as mode (mode)}
		<button
			type="button"
			class={cn(
				"gap-1.5 rounded-md px-3 py-1 text-xs font-medium tracking-wide whitespace-nowrap uppercase transition-colors duration-150 ease-out",
				mode === activeMode
					? "bg-accent dark:text-foreground light:text-card"
					: "text-foreground/70 hover:text-foreground",
			)}
			onclick={() => handleModeChange(mode)}
		>
			{mode}
		</button>
	{/each}
</div>

Props

SplitReveal

PropTypeDefault
mode
"lines""words""chars" "lines"
class
string ""
as
keyof HTMLElementTagNameMap "div"
config
SplitRevealConfig DEFAULT_CONFIG
delay
number 0
triggerOnScroll
boolean false
scrollElement
stringHTMLElementnull undefined

SplitRevealConfig

KeyTypeDefault
lines.duration
number 0.8
lines.stagger
number 0.08
words.duration
number 0.6
words.stagger
number 0.06
chars.duration
number 0.4
chars.stagger
number 0.008