---
title: Text block effect
description: A coloured block sweeps each line in.
category: Text
tier: free
url: https://ui.dimaac.com/components/text-block-effect
registry: https://ui.dimaac.com/r/text-block-effect.json
---

# Text block effect

A paragraph or heading cut into lines, where a block of colour slides across each line, the words appear underneath it and the block slides away. The blocks fit the words exactly, whether the text is left, centred or right aligned, and can travel in any of four directions, one line at a time or covering everything first. It uses GSAP SplitText with autoSplit, so the lines are cut again when the width changes or the web font loads, and everything is put back the way it was on unmount. It needs no section around it: the text starts by itself when it scrolls into view. It takes an optional scroller for inner scroll areas, can play again every time it comes back into view, and shows the text as it is when the visitor prefers reduced motion.

## Install

With the shadcn CLI:

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

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

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-block-effect.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 { TextBlockEffect } from "@/components/dimaac/text-block-effect". Give its parent a size: it fills it.

## Usage

```tsx
import { TextBlockEffect } from "@/components/dimaac/text-block-effect";

<TextBlockEffect children={children} />
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` (required) | `string` | - | The text to show. Plain text only (the lines are cut from it). |
| `as` | `"h1" \| "h2" \| "h3" \| "p"` | `"p"` | The tag to render: a page title, a section title or a paragraph. |
| `blockColor` | `string` | `"#DDFC3E"` | The colour of the sliding blocks. |
| `textColor` | `string` | `""` | The colour of the text. Empty keeps whatever colour the surrounding page gives it. |
| `direction` | `"right" \| "left" \| "down" \| "up"` | `"right"` | The way the blocks travel across a line before they leave again. |
| `mode` | `"line" \| "cover"` | `"line"` | "line" reveals one line after another. "cover" covers every line first, then uncovers them all. |
| `duration` | `number` | `0.45` | How long one block takes to slide across (or off) a line, in seconds. |
| `stagger` | `number` | `0.3` | The wait between one line starting and the next, in seconds. |
| `replay` | `boolean` | `false` | Play the reveal again each time the text scrolls back into view from above. |
| `start` | `string` | `"top 80%"` | When the reveal starts: "<element edge> <viewport edge>", e.g. "top 80%". |
| `scroller` | `string \| HTMLElement` | - | The scrolling element. Leave it out to use the page; give it a selector or an element for an inner scroller. |
| `className` | `string` | `""` | Extra classes: put the font size, weight, alignment and line height here. |

## Credits

- Background photo: stacy, Lummi (https://www.lummi.ai/photo/silhouette-with-sunglasses-wd3ut), Lummi License

## Source

### text-block-effect.tsx → `components/dimaac/text-block-effect.tsx`

```tsx
"use client";

import { createElement, useRef } from "react";
import { gsap } from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger";
import { SplitText } from "gsap/SplitText";
import { useGSAP } from "@gsap/react";

// Text that is revealed behind a coloured block. Each line gets a block that slides across it,
// the words appear while the block covers them, and the block slides away to show the line.
// The text stays real text: selectable, and read as one sentence by screen readers.
// It starts by itself when it scrolls into view, so it does not need a section around it.

if (typeof window !== "undefined") gsap.registerPlugin(useGSAP, ScrollTrigger, SplitText);

export type TextBlockEffectProps = {
  /** The text to show. Plain text only (the lines are cut from it). */
  children: string;
  /** The tag to render: a page title, a section title or a paragraph. */
  as?: "h1" | "h2" | "h3" | "p";
  /** The colour of the sliding blocks. */
  blockColor?: string;
  /** The colour of the text. Empty keeps whatever colour the surrounding page gives it. */
  textColor?: string;
  /** The way the blocks travel across a line before they leave again. */
  direction?: "right" | "left" | "down" | "up";
  /** "line" reveals one line after another. "cover" covers every line first, then uncovers them all. */
  mode?: "line" | "cover";
  /** How long one block takes to slide across (or off) a line, in seconds. */
  duration?: number;
  /** The wait between one line starting and the next, in seconds. */
  stagger?: number;
  /** Play the reveal again each time the text scrolls back into view from above. */
  replay?: boolean;
  /** When the reveal starts: "<element edge> <viewport edge>", e.g. "top 80%". */
  start?: string;
  /** The scrolling element. Leave it out to use the page; give it a selector or an element for an inner scroller. */
  scroller?: string | HTMLElement;
  /** Extra classes: put the font size, weight, alignment and line height here. */
  className?: string;
};

export function TextBlockEffect({
  children,
  as = "p",
  blockColor = "#DDFC3E",
  textColor = "",
  direction = "right",
  mode = "line",
  duration = 0.45,
  stagger = 0.3,
  replay = false,
  start = "top 80%",
  scroller,
  className = "",
}: TextBlockEffectProps) {
  const textRef = useRef<HTMLElement>(null);

  useGSAP(
    () => {
      const element = textRef.current;
      if (!element) return;

      // The text is hidden until it is split, so you never see it jump. Show it again either way.
      element.style.visibility = "visible";

      // Reduced motion: leave the text exactly as written, fully readable
      if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) return;

      // Sideways directions use scaleX, up and down use scaleY.
      // A block grows from the side it comes from, then shrinks towards the opposite side.
      const sideways = direction === "right" || direction === "left";
      const axis = sideways ? "scaleX" : "scaleY";
      const origins = { right: ["left center", "right center"], left: ["right center", "left center"], down: ["center top", "center bottom"], up: ["center bottom", "center top"] } as const;
      const [growFrom, shrinkTo] = origins[direction];

      const split = SplitText.create(element, {
        type: "lines",
        linesClass: "text-block-line",
        // Cut the lines again when the width changes or the web font arrives
        autoSplit: true,
        onSplit(self) {
          const align = getComputedStyle(element).textAlign;
          const pieces: { text: HTMLElement; block: HTMLElement }[] = [];

          self.lines.forEach((line) => {
            // The line shrinks to the width of its words, so the block is exactly as wide as the text
            const lineBox = line as HTMLElement;
            lineBox.style.display = "block";
            lineBox.style.position = "relative";
            lineBox.style.width = "fit-content";
            lineBox.style.maxWidth = "100%";
            lineBox.style.textAlign = "start";
            if (align === "center") lineBox.style.marginInline = "auto";
            else if (align === "right" || align === "end") lineBox.style.marginLeft = "auto";

            // The words go in their own wrapper, so they can be hidden without hiding the block
            const text = document.createElement("span");
            while (lineBox.firstChild) text.appendChild(lineBox.firstChild);
            lineBox.appendChild(text);

            // A touch bigger than the line, so no sliver of text shows around the edges
            const block = document.createElement("span");
            block.setAttribute("aria-hidden", "true");
            block.style.cssText = `position:absolute;left:-1%;top:0;width:102%;height:102%;pointer-events:none;background:${blockColor};`;
            lineBox.appendChild(block);

            pieces.push({ text, block });
          });

          gsap.set(pieces.map((p) => p.text), { opacity: 0 });
          gsap.set(pieces.map((p) => p.block), { [axis]: 0, transformOrigin: growFrom });

          const timeline = gsap.timeline({
            scrollTrigger: { trigger: element, scroller, start, toggleActions: replay ? "play none none reset" : "play none none none" },
          });

          const grow = (block: HTMLElement, at: number) => {
            timeline.set(block, { transformOrigin: growFrom }, at);
            timeline.to(block, { [axis]: 1, duration, ease: "power2.inOut" }, at);
          };
          const shrink = (block: HTMLElement, text: HTMLElement, at: number) => {
            // The words are shown at the moment the block is fully over them
            timeline.set(text, { opacity: 1 }, at);
            timeline.set(block, { transformOrigin: shrinkTo }, at);
            timeline.to(block, { [axis]: 0, duration, ease: "power2.inOut" }, at);
          };

          if (mode === "cover") {
            // Every line is covered first, one after another, then they are all uncovered
            pieces.forEach((piece, i) => grow(piece.block, i * stagger));
            const covered = (pieces.length - 1) * stagger + duration;
            pieces.forEach((piece, i) => shrink(piece.block, piece.text, covered + i * stagger));
          } else {
            // Each line is covered and uncovered in turn, the next one starting a moment later
            pieces.forEach((piece, i) => {
              grow(piece.block, i * stagger);
              shrink(piece.block, piece.text, i * stagger + duration);
            });
          }

          // Returning the timeline lets SplitText keep it in step when it re-splits
          return timeline;
        },
      });

      return () => split.revert();
    },
    { scope: textRef, dependencies: [children, as, blockColor, direction, mode, duration, stagger, replay, start, scroller], revertOnUpdate: true },
  );

  // The key makes React build a fresh element when the text or tag changes, because SplitText
  // rewrites the inside of the old one.
  return createElement(as, { ref: textRef, key: `${as}:${children}`, className, style: { visibility: "hidden", ...(textColor ? { color: textColor } : null) } }, children);
}
```

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

```tsx
"use client";

import { TextBlockEffect, type TextBlockEffectProps } from "@/components/dimaac/text-block-effect";

// Four short screens of type, each one a different kind of text. Every block uses the playground settings.
// Photo: stacy on Lummi (Lummi License).

const body = "font-[family-name:'Bricolage_Grotesque',sans-serif] text-[#ededed]";

export default function Demo(props: Partial<TextBlockEffectProps>) {
  const { className: _className, children: _children, as: _as, ...shared } = props;
  return (
    <div className="min-h-dvh bg-[#0b0b0f]">
      <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,300..700&display=swap" precedence="default" />

      <section className="relative flex min-h-dvh w-full items-center justify-center overflow-hidden px-8">
        <p className="absolute top-6 left-6 font-mono text-[11px] tracking-wide text-white/50 uppercase md:left-12">Scroll</p>
        <TextBlockEffect {...shared} start="top 100%" className={`max-w-[600px] text-center text-[clamp(1.75rem,3vw,2.75rem)] leading-[1.6] ${body}`}>
          We believe in the quiet power of ideas. The ones that sit with you long after you have looked away.
        </TextBlockEffect>
      </section>

      <section className="relative flex min-h-dvh w-full items-center justify-center overflow-hidden px-8">
        <img src="https://ui.dimaac.com/media/dark/blue-silhouette-3x2.jpg" alt="" className="absolute inset-0 h-full w-full object-cover object-center" style={{ filter: "brightness(0.6) saturate(0.85)" }} />
        <div className="pointer-events-none absolute inset-0 bg-[#0b0b0f]/50" />
        <TextBlockEffect {...shared} className={`relative z-[2] max-w-[600px] text-center text-[clamp(1.75rem,3vw,2.75rem)] leading-[1.6] ${body}`}>
          Some things are felt before they are understood. We craft those in-between moments, still, sharp and unforgettable.
        </TextBlockEffect>
      </section>

      <section className="relative flex min-h-dvh w-full flex-col justify-center gap-10 px-8 md:px-[8vw]">
        <TextBlockEffect {...shared} as="h2" className={`max-w-[11ch] text-left text-[clamp(3rem,9vw,8rem)] leading-[1.15] font-medium tracking-[-0.03em] ${body}`}>
          Closer to what matters
        </TextBlockEffect>
        <TextBlockEffect {...shared} className={`max-w-[34ch] self-end text-right text-[clamp(1rem,1.6vw,1.375rem)] leading-[1.7] ${body} opacity-80`}>
          Not louder. Not faster. Just closer to something that actually matters, set in type and let in one line at a time.
        </TextBlockEffect>
      </section>

      <section className="relative flex min-h-[60dvh] w-full items-center justify-center overflow-hidden px-8">
        <TextBlockEffect {...shared} className={`max-w-[600px] text-center text-[clamp(1.75rem,3vw,2.75rem)] leading-[1.6] ${body}`}>
          Scroll back up and it plays again, if replay is on.
        </TextBlockEffect>
      </section>
    </div>
  );
}
```

## Agent prompt

```text
Add the Text block effect component (<TextBlockEffect />) from DiMaac UI to this project.

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

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

Then use it like this:
import { TextBlockEffect } from "@/components/dimaac/text-block-effect";
<TextBlockEffect children={children} />

If the shadcn CLI isn't set up here, fetch the registry JSON above, write files[0].content to components/dimaac/text-block-effect.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
```
