Lab // Index

Total: 07

Component // Text

03 of 07

Dia TextNew

Text written in by a band of colour sweeping across it, then left in its base colour. A web port of the Dia-style text reveal, with no dependencies

Demo // Live

Interactive
Design engineering

Install // Steps

Total: 01

Step 01

Copy and paste the following code into your project.

One file, React only. The sweep runs on the Web Animations API, so there is nothing to install.

import { DiaText } from "@/components/craft/dia-text";

export default function MyPage() {
  return (
    <div className="flex min-h-screen flex-col items-center justify-center gap-10 p-8">
      {/* One line, revealed once. Change `text` and it sweeps again. */}
      <DiaText text="Hello, world" className="text-5xl font-semibold" />

      {/* Several lines, cycling */}
      <DiaText
        text={["Design engineering", "Details, on purpose", "Built end to end"]}
        loop
        className="text-5xl font-semibold"
      />

      {/* Your own colours and pace */}
      <DiaText
        text="Monochrome works too"
        sweepColors={["#ffffff", "#8a8a8a"]}
        baseColor="#111111"
        duration={900}
        bandRatio={0.5}
        className="text-3xl"
      />
    </div>
  );
}

Spec // Features

Total: 06
  • 01

    Works on real text

    The text is the mask, so it stays selectable, readable by screen readers and free to wrap

  • 02

    Sweeps again when the text changes

  • 03

    Cycles through several lines

    Pass an array with loop; each line slides out and the next is swept in

  • 04

    Custom colours, band width and pace

  • 05

    Respects reduced motion

    The text simply appears

  • 06

    No dependencies

Spec // Props

Total: 10
Dia Text props
PropTypeDefaultDescription
textstring | string[]-The line to reveal, or several to cycle through
sweepColorsstring[]5 coloursColours inside the moving band
baseColorstringcurrentColorWhat the text settles into
durationnumber1500Length of one sweep, in ms
delaynumber0Wait before the sweep starts, in ms
loopbooleanfalseReplay, moving to the next text if there are several
loopDelaynumber500Pause between sweeps, in ms
bandRationumber0.34Band width as a fraction of the text width
autoPlaybooleantrueSet false to hold the text hidden
onSweepEnd(index) => void-Called when a sweep finishes