Back to TextsYou are on Rolling Text.

Rolling Text

Letters roll over themselves like a split-flap board.

Available inAvailable in React, Vue, Svelte, Solid, JavaScript· All five frameworks
PrequelUI

Libraries

PrequelUI

Motion

Spring + short tween

Reduced motion

Fade in place
rolling-text.tsx
Play with the real component, then read the code it ships with.All components
01

Installation

Installing for React·components/prequelui/rolling-text.tsx

Add the component

npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/rolling-text.json
npmthe default on every machine

First component? Set up your project first

Frameworks

The live preview is React. Each tab below is the file that ships for that framework, with the same durations, springs and reduced-motion rule.

5 runtimes
rolling-text.tsx
"use client";

import * as React from "react";
import { motion, type Transition } from "motion/react";
import { cn } from "@/lib/utils";
import {
  splitGraphemes,
  srOnlyStyle,
  useReduceMotion,
  useSeen,
  useTempo,
  useTempoTransition,
} from "./motion";

export type RollingTextProps = Omit<React.ComponentProps<"span">, "children"> & {
  text: string;
  transition?: Transition;
  delay?: number;
  inView?: boolean;
  inViewOnce?: boolean;
};

const CHAR: React.CSSProperties = {
  position: "absolute",
  display: "inline-block",
  backfaceVisibility: "hidden",
};

export function RollingText({
  text,
  transition,
  delay = 0,
  inView = false,
  inViewOnce = true,
  className,
  ...props
}: RollingTextProps) {
  const reduce = useReduceMotion();
  const tempo = useTempo();
  const ref = React.useRef<HTMLSpanElement>(null);
  const seen = useSeen(ref, inView, inViewOnce);
  const tween = useTempoTransition(
    transition ?? { duration: 0.5, delay: 0.1, ease: [0.23, 1, 0.32, 1] },
  );
  const step = Number(tween.delay ?? 0) * tempo;
  const rolled = seen || reduce;

  const words = React.useMemo(
    () =>
      text
        .split(/(\s+)/)
        .filter(Boolean)
        .map((part) =>
          /^\s+$/.test(part)
            ? { space: true as const, part }
            : { space: false as const, chars: splitGraphemes(part) },
        ),
    [text],
  );

  let charIndex = 0;

  return (
    <span
      ref={ref}
      data-slot="rolling-text"
      className={cn("inline", className)}
      {...props}
    >
      <span aria-hidden="true">
        {words.map((word, wordIndex) => {
          if (word.space) {
            return <span key={`space-${wordIndex}`}>{word.part}</span>;
          }
          return (
            <span
              key={`word-${wordIndex}`}
              className="inline-block whitespace-nowrap"
            >
              {word.chars.map((char, index) => {
                const charDelay = delay / 1000 + charIndex++ * step;
                const label = char === " " ? "\u00A0" : char;
                return (
                  <span
                    key={`char-${wordIndex}-${index}`}
                    className="relative inline-block"
                    style={{ perspective: 9999999, transformStyle: "preserve-3d" }}
                  >
                    <motion.span
                      style={{ ...CHAR, transformOrigin: "50% 25%" }}
                      initial={reduce ? false : { rotateX: 0 }}
                      animate={rolled ? { rotateX: 90 } : undefined}
                      transition={
                        reduce ? { duration: 0 } : { ...tween, delay: charDelay }
                      }
                    >
                      {label}
                    </motion.span>
                    <motion.span
                      style={{ ...CHAR, transformOrigin: "50% 100%" }}
                      initial={reduce ? false : { rotateX: 90 }}
                      animate={rolled ? { rotateX: 0 } : undefined}
                      transition={
                        reduce
                          ? { duration: 0 }
                          : { ...tween, delay: charDelay + 0.3 * tempo }
                      }
                    >
                      {label}
                    </motion.span>
                    <span className="invisible">{label}</span>
                  </span>
                );
              })}
            </span>
          );
        })}
      </span>
      <span className="sr-only" style={srOnlyStyle()}>
        {text}
      </span>
    </span>
  );
}

Install

npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/rolling-text.json
npmthe default on every machine

Dependencies

motion lucide-react

The registry keeps the component source, its motion tokens and the reduced-motion branch together, so the install never pulls a different animation from the preview.

02

Usage

Import the component and compose it exactly like the primitive it wraps. Motion is enabled by default; the tempo prop scales every duration and softens every spring.

rolling-text.tsx
import { RollingText } from "@/components/prequelui/rolling-text";

export default function Demo() {
  return (
    <RollingText
      text="MOVE WITH PURPOSE"
      className="text-4xl font-semibold tracking-[0.06em]"
    />
  );
}
import { RollingText } from "@/components/prequelui/rolling-text";

export function Variant() {
  return (
    <RollingText tempo={1.2}>
      …
    </RollingText>
  );
}
03

Animation

Every character is a split-flap. The front face rotates away from its top edge while the back face falls into place from its bottom edge, character by character with a tenth of a second between them.

  • Character tween: 500 ms ease-out with a 100 ms step.
  • The back face starts 300 ms after its front face.
  • Perspective is pushed very far to keep the glyphs the same size.
  • The full string is exposed to assistive technology as one label.
500 ms ease-outstep 100 msback +300 msrotateX 90°
04

API Reference

Each part accepts the usual HTML props in addition to the motion props below. No accessibility prop is hidden behind the animation layer.

RollingText

PropTypeDefault
textstring—
delaynumber0
inViewbooleanfalse
inViewOncebooleantrue
transitionTransitioncomponent spring or tween

Next component

Rotating Text

Words leave upward while the next one rises into place.