Text Reveal
Masked line, word or letter reveals powered by GSAP SplitText.
gsap@gsap/reactMIT · free
Motion that makes your site feel alive.
Every word arrives a beat after the last, softly coming into focus.
Usage
import { TextReveal } from "@/components/text-reveal";
<TextReveal as="h1" split="lines">
Motion that makes your site feel alive.
</TextReveal>
<TextReveal split="words" blur>Softly, one word at a time.</TextReveal>
<TextReveal split="chars" trigger="load">Hello</TextReveal>Installation
npx shadcn@latest add https://ombakui.com/r/text-reveal.jsonInstall the dependencies:
npm install gsap @gsap/reactCopy this into components/text-reveal.tsx. It uses cn() from @/lib/utils.
components/text-reveal.tsx
"use client";
import { useRef, type ElementType, type ReactNode } from "react";
import { gsap } from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger";
import { SplitText } from "gsap/SplitText";
import { useGSAP } from "@gsap/react";
import { cn } from "@/lib/utils";
if (typeof window !== "undefined") gsap.registerPlugin(ScrollTrigger, SplitText, useGSAP);
export type TextRevealProps = {
children: ReactNode;
/** HTML tag to render. Default "h2" */
as?: ElementType;
/** Split into lines, words or characters. Default "lines" */
split?: "lines" | "words" | "chars";
/** "scroll" plays when the text enters the viewport, "load" plays on mount. Default "scroll" */
trigger?: "scroll" | "load";
/** Seconds per piece. Default 1 */
duration?: number;
/** Seconds between pieces. Default depends on split */
stagger?: number;
/** Seconds before starting. Default 0 */
delay?: number;
/** Blur-to-sharp while revealing. Default false */
blur?: boolean;
/** ScrollTrigger start position. Default "top 85%" */
start?: string;
className?: string;
};
const STAGGER = { lines: 0.08, words: 0.04, chars: 0.02 } as const;
/**
* Masked text reveal: lines, words or letters slide up from behind an invisible mask.
* Re-splits on resize and after fonts load. Shows plain text for reduced-motion users.
*/
export function TextReveal({
children,
as: Tag = "h2",
split = "lines",
trigger = "scroll",
duration = 1,
stagger,
delay = 0,
blur = false,
start = "top 85%",
className,
}: TextRevealProps) {
const ref = useRef<HTMLElement>(null);
useGSAP(
() => {
const el = ref.current;
if (!el || window.matchMedia("(prefers-reduced-motion: reduce)").matches) return;
SplitText.create(el, {
type: split === "chars" ? "lines,words,chars" : split === "words" ? "lines,words" : "lines",
mask: "lines",
autoSplit: true,
onSplit(self) {
const targets = split === "chars" ? self.chars : split === "words" ? self.words : self.lines;
return gsap.fromTo(
targets,
{ yPercent: 115, opacity: blur ? 0 : 1, filter: blur ? "blur(8px)" : undefined },
{
yPercent: 0,
opacity: 1,
filter: blur ? "blur(0px)" : undefined,
duration,
delay,
stagger: stagger ?? STAGGER[split],
ease: "expo.out",
scrollTrigger: trigger === "scroll" ? { trigger: el, start, once: true } : undefined,
},
);
},
});
},
{ scope: ref, dependencies: [split, trigger, duration, stagger, delay, blur, start] },
);
return (
<Tag ref={ref} className={cn(className)}>
{children}
</Tag>
);
}Usage
import { TextReveal } from "@/components/text-reveal";
<TextReveal as="h1" split="lines">
Motion that makes your site feel alive.
</TextReveal>
<TextReveal split="words" blur>Softly, one word at a time.</TextReveal>
<TextReveal split="chars" trigger="load">Hello</TextReveal>Props
| Prop | Type | Default | Description |
|---|---|---|---|
| children* | ReactNode | – | |
| as | ElementType | "h2" | HTML tag to render. |
| split | "lines" | "words" | "chars" | "lines" | Split into lines, words or characters. |
| trigger | "scroll" | "load" | "scroll" | "scroll" plays when the text enters the viewport, "load" plays on mount. |
| duration | number | 1 | Seconds per piece. |
| stagger | number | depends on split | Seconds between pieces. |
| delay | number | 0 | Seconds before starting. |
| blur | boolean | false | Blur-to-sharp while revealing. |
| start | string | "top 85%" | ScrollTrigger start position. |
| className | string | – |