---
title: Text Loader
description: Letters rise out of a mask, fill with a gradient, leave, and the panel lifts away.
category: Loaders
tier: free
url: https://ui.dimaac.com/components/text-loader
registry: https://ui.dimaac.com/r/text-loader.json
---

# Text Loader

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.

## Install

With the shadcn CLI:

```bash
npx shadcn@latest add https://ui.dimaac.com/r/text-loader.json
pnpm dlx shadcn@latest add https://ui.dimaac.com/r/text-loader.json
bunx --bun shadcn@latest add https://ui.dimaac.com/r/text-loader.json
```

With the `@dimaac` namespace in components.json: `npx shadcn@latest add @dimaac/text-loader`

Dependencies:

```bash
pnpm add gsap @gsap/react
npm install gsap @gsap/react
```

By hand:

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.

## Usage

```tsx
import { TextLoader } from "@/components/dimaac/text-loader";

<TextLoader />
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `text` | `string` | `"DIMAAC"` | The word the loader spells out. One letter is one animated piece. |
| `gradientColors` | `string[]` | `DEFAULT_COLORS` | Colours of the gradient that fills the letters (45 degrees, one gradient per letter). Two or more. |
| `backgroundColor` | `string` | `"#17171a"` | Colour of the panel. |
| `ghostColor` | `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. |
| `duration` | `{` | - | How long each step takes, in seconds. Any you leave out keep their default. |
| `slideUp` | `number` | - | Letters rising into view. |
| `reveal` | `number` | - | The gradient filling the letters. |
| `slideDown` | `number` | - | Letters leaving through the top. |
| `delays` | `{` | - | The pauses in between, in seconds. Any you leave out keep their default. |
| `stagger` | `number` | - | Gap between one letter and the next. |
| `betweenAnimations` | `number` | - | Pause between the letters landing and the gradient starting. |
| `beforeSlideDown` | `number` | - | Pause between the gradient finishing and the letters leaving. |
| `fullscreen` | `boolean` | `false` | Cover the whole window (position: fixed) instead of filling the box it sits in. |
| `replayKey` | `number` | `0` | Change 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. |
| `className` | `string` | `""` | Extra classes for the panel. |

## Credits

- Page photo: Viri Gutiérrez, Lummi (https://www.lummi.ai/photo/an-empty-snowy-mountain-with-pink-sunrise-on-the-hori-270fdea6-887e-4d89-8205-3eab907f3fb0-HgoCN), Lummi License (free for personal and commercial use)

## Source

### text-loader.tsx → `components/dimaac/text-loader.tsx`

```tsx
"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>
  );
}
```

### demo.tsx (the demo on the page, not installed)

```tsx
"use client";

import { useEffect, useRef, useState } from "react";
import { TextLoader, type TextLoaderProps } from "@/components/dimaac/text-loader";

// The page the loader opens. The photo is from Lummi (Lummi License: free for personal and commercial use).
const photo = "https://ui.dimaac.com/media/nature/alpine-dawn-16x9.jpg";

const palettes: Record<string, string[]> = {
  ember: ["#ff0000", "#ff3333", "#ff6600", "#cc0000"],
  ocean: ["#0066ff", "#3399ff", "#00ccff", "#0099cc"],
  dusk: ["#8b5cf6", "#a78bfa", "#c084fc", "#ddd6fe"],
  forest: ["#22c55e", "#16a34a", "#15803d", "#166534"],
  lime: ["#d9f99d", "#bef264", "#a3e635", "#84cc16"],
};

// The playground passes flat values, so the demo folds them back into the component's objects
type DemoProps = {
  text: string;
  palette: string;
  backgroundColor: string;
  slideUp: number;
  reveal: number;
  slideDown: number;
  stagger: number;
  betweenAnimations: number;
  beforeSlideDown: number;
} & Pick<TextLoaderProps, "className">;

export default function Demo({ text, palette = "ember", backgroundColor, slideUp, reveal, slideDown, stagger, betweenAnimations, beforeSlideDown, className }: Partial<DemoProps>) {
  const [replayKey, setReplayKey] = useState(0);

  // Colours are plain styles and the panel is gone once the run ends, so replay when they change
  const firstRender = useRef(true);
  useEffect(() => {
    if (firstRender.current) {
      firstRender.current = false;
      return;
    }
    setReplayKey((key) => key + 1);
  }, [palette, backgroundColor]);

  return (
    <div className="relative h-full w-full overflow-hidden bg-[#14161c] text-[#f4f1ea]">
      {/* The page underneath */}
      <img src={photo} alt="Snow-covered mountains at sunrise under a pink and orange sky" className="absolute inset-0 h-full w-full object-cover" decoding="async" />
      <div className="absolute inset-0 bg-gradient-to-t from-black/60 via-black/10 to-black/30" />

      <div className="absolute inset-x-6 bottom-8 flex flex-col items-start gap-6 md:inset-x-10 md:bottom-10 md:flex-row md:items-end md:justify-between">
        <h1 className="max-w-[12ch] text-[clamp(44px,8vw,120px)] leading-[0.92] font-medium tracking-[-0.045em]">First light, high up</h1>
        <button
          type="button"
          onClick={() => setReplayKey((key) => key + 1)}
          className="cursor-pointer rounded-full border border-white/40 bg-white/10 px-5 py-2.5 font-mono text-[12px] tracking-wide uppercase backdrop-blur-md transition-colors hover:bg-white/25 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white"
        >
          Replay loader
        </button>
      </div>

      <TextLoader
        text={text}
        gradientColors={palettes[palette] ?? palettes.ember}
        backgroundColor={backgroundColor}
        duration={{ slideUp, reveal, slideDown }}
        delays={{ stagger, betweenAnimations, beforeSlideDown }}
        replayKey={replayKey}
        className={className}
      />
    </div>
  );
}
```

## Agent prompt

```text
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
```
