Components

Split Text

A split text animation for React and Tailwind CSS: letters or words stagger in with a rise, drop, blur or fade when the text scrolls into view. The finished text is server-rendered for SEO, lines only break between words, and screen readers get the whole string.

  • Letters or words
  • Stagger on view
  • Server-rendered text
  • No re-renders
  • prefers-reduced-motion

Midnight, rendered.

Installation

$ npx shadcn@latest add https://duskui.com/r/split-text.json

Usage

headline.tsx
import { SplitText } from "@/components/dusk/text/split-text"

export function Headline() {
  return (
    <SplitText as="h1" effect="rise" className="text-6xl font-bold">
      Hello, night shift.
    </SplitText>
  )
}

Examples

Effects

effect picks how each piece enters: rise, drop, blur or fade. Tune the rhythm with stagger, duration and delay.

Rise up

Drop in

Out of focus

Quiet fade

Words, replayed

by="words" animates whole words, which suits paragraphs. With once={false} it replays every time it scrolls back into view.

Words arrive one after another every time this paragraph scrolls back into view, and line breaks only ever happen between them.

API Reference

Also accepts any HTML attribute for the rendered element.

PropTypeDefaultDescription
childrenstring—The text to animate. Plain text only.
as"span" | "p" | "div" | "strong" | "h1" … "h6""span"Element to render. Use a heading level for titles.
by"letters" | "words""letters"Animate each letter or each word.
effect"rise" | "drop" | "blur" | "fade""rise"How each piece enters.
staggernumber0.03 (letters) / 0.07 (words)Seconds between pieces.
delaynumber0Seconds before the first piece.
durationnumber0.6Seconds each piece takes.
oncebooleantruePlay only the first time. When false it replays on every entry.
amountnumber0.4How much of the element must be visible to start (0–1).

Accessibility

  • The server renders the finished text, so crawlers and no-JS visitors always see it; pieces are hidden just before the first client paint.
  • In word mode the words are the real text. In letter mode a visually hidden copy carries the string and the letters are aria-hidden, because some screen readers read split letters one at a time.
  • Letters are grouped per word, so lines only ever break between words. Letters are split by grapheme, so emoji and accents stay intact.
  • Pieces animate with Motion directly on the DOM, with no React state per letter.
  • With prefers-reduced-motion the text is shown immediately.