← Components

Text Loader

Letters rise out of a mask, fill with a gradient, leave, and the panel lifts away.

Loaders · FreeInstall ↓
Open preview ↗
Loading the demoNew tab ↗

Customize

#17171a
0.60 s
0.80 s
0.60 s
0.050 s
0.30 s
0.50 s
Your code
<TextLoader />

Changes show live and stay in the address, so a link keeps them.

Code

"use client";

import { useEffect, useRef } from "react";
import { gsap } from "gsap";
import { useGSAP } from "@gsap/react";

// A preloader. The letters rise one by one out of a mask, a gradient wipes up through each of them,
// they leave through the top, and then the whole panel lifts off the page. It uses the font of the
// page it sits in, so there is no font to install.

export type TextLoaderProps = {
  /** The word the loader spells out. One letter is one animated piece. */
  text?: string;
  /** Colours of the gradient that fills the letters (45 degrees, one gradient per letter). Two or more. */
  gradientColors?: string[];
  /** Colour of the panel. */
  backgroundColor?: string;
  /** Colour of the letters before the gradient fills them. Leave it out and it follows the panel: a light tint on a dark panel, a dark tint on a light one. */
  ghostColor?: string;
  /** How long each step takes, in seconds. Any you leave out keep their default. */
  duration?: {
    /** Letters rising into view. */
    slideUp?: number;
    /** The gradient filling the letters. */
    reveal?: number;
    /** Letters leaving through the top. */
    slideDown?: number;
  };
  /** The pauses in between, in seconds. Any you leave out keep their default. */
  delays?: {
    /** Gap between one letter and the next. */
    stagger?: number;
    /** Pause between the letters landing and the gradient starting. */
    betweenAnimations?: number;
    /** Pause between the gradient finishing and the letters leaving. */
    beforeSlideDown?: number;
  };
  /** Cover the whole window (position: fixed) instead of filling the box it sits in. */
  fullscreen?: boolean;
  /** Change this number to play the loader again. */
  replayKey?: number;
  /** Called once the panel has left the screen. A new function on every render is fine. */
  onComplete?: () => void;
  /** Extra classes for the panel. */
  className?: string;
};

// Module constants, so the defaults are the same object on every render
const DEFAULT_COLORS = ["#ff0000", "#ff3333", "#ff6600", "#cc0000"];
const DEFAULT_DURATION = { slideUp: 0.6, reveal: 0.8, slideDown: 0.6 };
const DEFAULT_DELAYS = { stagger: 0.05, betweenAnimations: 0.3, beforeSlideDown: 0.5 };

// Like { ...defaults, ...given }, except a value that is undefined falls back to its default
function withDefaults<T extends Record<string, number>>(defaults: T, given: Partial<T> = {}): T {
  const merged = { ...defaults };
  for (const key of Object.keys(defaults) as (keyof T)[]) {
    const value = given[key];
    if (value !== undefined) merged[key] = value;
  }
  return merged;
}

// Picks the ghost letters from the panel colour, so a light panel never hides them.
// Only #rgb and #rrggbb are read; any other colour format falls back to the light tint.
function ghostFor(background: string): string {
  const hex = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(background.trim())?.[1];
  if (!hex) return "rgba(255, 255, 255, 0.2)";
  const full = hex.length === 3 ? Array.from(hex, (c) => c + c).join("") : hex;
  const channel = (i: number) => parseInt(full.slice(i, i + 2), 16);
  const [r, g, b] = [channel(0), channel(2), channel(4)];
  const light = (0.299 * r + 0.587 * g + 0.114 * b) / 255 > 0.6;
  return light ? "rgba(0, 0, 0, 0.14)" : "rgba(255, 255, 255, 0.2)";
}

export function TextLoader({
  text = "DIMAAC",
  gradientColors = DEFAULT_COLORS,
  backgroundColor = "#17171a",
  ghostColor,
  duration,
  delays,
  fullscreen = false,
  replayKey = 0,
  onComplete,
  className = "",
}: TextLoaderProps) {
  const panelRef = useRef<HTMLDivElement>(null);

  // A partly filled object still works: whatever is missing comes from the defaults
  const { slideUp, reveal, slideDown } = withDefaults(DEFAULT_DURATION, duration);
  const { stagger, betweenAnimations, beforeSlideDown } = withDefaults(DEFAULT_DELAYS, delays);

  // The newest onComplete lives in a ref. The animation reads it when it ends, so a parent that
  // re-renders (and passes a new function) never restarts the loader.
  const onCompleteRef = useRef(onComplete);
  useEffect(() => {
    onCompleteRef.current = onComplete;
  });

  const letters = Array.from(text);
  const gradient = `linear-gradient(45deg, ${(gradientColors.length > 1 ? gradientColors : DEFAULT_COLORS).join(", ")})`;

  useGSAP(
    () => {
      const panel = panelRef.current;
      if (!panel) return;
      const glyphs = gsap.utils.toArray<HTMLElement>("[data-glyph]", panel);
      const fills = gsap.utils.toArray<HTMLElement>("[data-fill]", panel);
      const finish = () => {
        // Off screen already, but also out of reach of the keyboard and screen readers
        gsap.set(panel, { visibility: "hidden" });
        onCompleteRef.current?.();
      };

      const mm = gsap.matchMedia();

      mm.add("(prefers-reduced-motion: no-preference)", () => {
        gsap.set(panel, { y: 0, yPercent: 0, visibility: "visible" });
        gsap.set(glyphs, { y: 0, yPercent: 110 });
        gsap.set(fills, { clipPath: "inset(100% 0% 0% 0%)" });

        const tl = gsap.timeline({ onComplete: finish });
        tl.to(glyphs, { yPercent: 0, duration: slideUp, stagger, ease: "power2.out" })
          .to(fills, { clipPath: "inset(0% 0% 0% 0%)", duration: reveal, delay: betweenAnimations, ease: "power1.inOut" })
          .to(glyphs, { yPercent: -110, duration: slideDown, stagger, delay: beforeSlideDown, ease: "power2.in" })
          .to(panel, { yPercent: -100, duration: 0.8, delay: 0.3, ease: "power2.inOut" }, "-=0.2");
      });

      // Reduced motion: nothing moves. The word shows filled for a moment, then the panel fades away.
      mm.add("(prefers-reduced-motion: reduce)", () => {
        gsap.set(panel, { y: 0, yPercent: 0, visibility: "visible", opacity: 1 });
        gsap.set(glyphs, { y: 0, yPercent: 0 });
        gsap.set(fills, { clipPath: "inset(0% 0% 0% 0%)" });
        gsap.to(panel, { opacity: 0, duration: 0.4, delay: 0.9, ease: "none", onComplete: finish });
      });

      return () => mm.revert();
    },
    // Only the numbers and the text restart it. Colours are plain styles, so they change live.
    { scope: panelRef, dependencies: [text, slideUp, reveal, slideDown, stagger, betweenAnimations, beforeSlideDown, replayKey], revertOnUpdate: true },
  );

  // One size rule: it grows with the panel's width, and shrinks for long words so they always fit
  const fontSize = `clamp(2rem, min(20cqi, ${(88 / (Math.max(letters.length, 3) * 0.66)).toFixed(2)}cqi), 8rem)`;

  return (
    <div
      ref={panelRef}
      role="status"
      className={`${fullscreen ? "fixed" : "absolute"} inset-0 z-50 flex items-center justify-center overflow-hidden ${className}`}
      style={{ backgroundColor, containerType: "inline-size" }}
    >
      <span className="sr-only">{text}</span>
      <div aria-hidden="true" className="flex overflow-hidden px-[0.04em]" style={{ fontSize, fontWeight: 700, lineHeight: 1.05, letterSpacing: "-0.01em" }}>
        {letters.map((letter, index) => (
          <span
            key={`${letter}-${index}`}
            data-glyph
            className="relative inline-block whitespace-pre"
            style={{ color: ghostColor ?? ghostFor(backgroundColor), transform: "translateY(110%)" }}
          >
            {letter}
            {/* The same letter on top, filled with the gradient and wiped in from the bottom */}
            <span
              data-fill
              className="absolute inset-0"
              style={{ backgroundImage: gradient, backgroundClip: "text", WebkitBackgroundClip: "text", WebkitTextFillColor: "transparent", clipPath: "inset(100% 0% 0% 0%)" }}
            >
              {letter}
            </span>
          </span>
        ))}
      </div>
    </div>
  );
}

The component. Installs to components/dimaac/text-loader.tsx.

Install

With the shadcn CLI

npx shadcn@latest add https://ui.dimaac.com/r/text-loader.json

It adds components/dimaac/text-loader.tsx and installs what it imports. With the @dimaac namespace in components.json (Docs) it's just npx shadcn@latest add @dimaac/text-loader.

By hand

npm install gsap @gsap/react
  1. Install the packages it uses: gsap, @gsap/react.
  2. Copy the component file below into components/dimaac/text-loader.tsx.
  3. It's styled with Tailwind v4 classes. If that folder sits outside the places Tailwind scans, add it with @source in your CSS.
  4. Import it with import { TextLoader } from "@/components/dimaac/text-loader". Give its parent a size: it fills it.

Props

PropTypeDefaultDescription
textstring"DIMAAC"The word the loader spells out. One letter is one animated piece.
gradientColorsstring[]DEFAULT_COLORSColours of the gradient that fills the letters (45 degrees, one gradient per letter). Two or more.
backgroundColorstring"#17171a"Colour of the panel.
ghostColorstring-Colour of the letters before the gradient fills them. Leave it out and it follows the panel: a light tint on a dark panel, a dark tint on a light one.
duration{-How long each step takes, in seconds. Any you leave out keep their default.
slideUpnumber-Letters rising into view.
revealnumber-The gradient filling the letters.
slideDownnumber-Letters leaving through the top.
delays{-The pauses in between, in seconds. Any you leave out keep their default.
staggernumber-Gap between one letter and the next.
betweenAnimationsnumber-Pause between the letters landing and the gradient starting.
beforeSlideDownnumber-Pause between the gradient finishing and the letters leaving.
fullscreenbooleanfalseCover the whole window (position: fixed) instead of filling the box it sits in.
replayKeynumber0Change this number to play the loader again.
onComplete() => void-Called once the panel has left the screen. A new function on every render is fine.
classNamestring""Extra classes for the panel.

Use with AI

Agent prompt

Paste it into Claude Code, Cursor or any coding agent, or open it straight in a chat. It carries your Customize settings.

Prompt
Add the Text Loader component (<TextLoader />) from DiMaac UI to this project.

Docs: https://ui.dimaac.com/components/text-loader
Source and dependencies (shadcn registry JSON): https://ui.dimaac.com/r/text-loader.json

Install it with:
npx shadcn@latest add https://ui.dimaac.com/r/text-loader.json

Then use it like this:
import { TextLoader } from "@/components/dimaac/text-loader";
<TextLoader />

If the shadcn CLI isn't set up here, fetch the registry JSON above, write files[0].content to components/dimaac/text-loader.tsx and install gsap, @gsap/react.
It uses Tailwind v4 classes, so make sure Tailwind scans that folder. Give its parent a size: it fills it. Keep light and dark mode working and keep its prefers-reduced-motion fallback.
Full index for agents: https://ui.dimaac.com/llms.txt

Files agents read

llms.txt
Every component and how to install it
text-loader.md
This page as Markdown: install, props and the full source
text-loader.json
The shadcn registry item

About

A word preloader. Each letter rises into view out of a mask, a gradient wipes up through all of them, they leave through the top, and then the whole panel slides off the screen to show the page underneath. It uses the font of the page it sits in (no font import), fills the box it is placed in or the whole window with the fullscreen prop, scales its type to the panel so long words still fit, and plays again whenever you change its replayKey. A parent that re-renders never restarts it. With reduced motion the word simply shows filled and the panel fades out. Ported from the first DiMaac UI, rebuilt without styled-jsx and without the Google Fonts import.

Installs to
components/dimaac/text-loader.tsx
Uses
gsap, @gsap/react
Tags
gsap, loader, preloader, text, gradient

Page photo by Viri Gutiérrez on Lummi (Lummi License (free for personal and commercial use)).