Skip to content
WANCRAFT

C.72Typography & Text

Masked Text

Display type used as a window onto a moving texture — gradient, grain, stripes or your image.

NewReactCSSTailwindintermediate

Overview

Masked Text clips an animated texture to the letterforms with background-clip: text. Choose a drifting periodic gradient, a gradient with stepped film grain, diagonal stripes, or your own image, which sways inside a small overscan. On a fine pointer the texture shifts slightly towards the cursor for a parallax feel. One requestAnimationFrame loop moves the background position and pauses offscreen and in hidden tabs. The text itself stays a real, selectable heading, and browsers without text clipping (or forced-colours mode) get solid ink-coloured text instead.

01Installation

Method 01 · Registry

CLI verified

Uses the shadcn CLI in a project initialised with shadcn init. Installs the file to components/ui/masked-text.tsx and adds its dependencies.

npx shadcn@latest add https://wancraft.my/r/masked-text.json

Method 02 · Copy and paste

  1. 1. No extra dependencies — React and Tailwind CSS only.
  2. 2. Copy the source from the Code tab into components/ui/masked-text.tsx.
  3. 3. Import it and adjust props.
Dependencies
None
Peer
react ≥ 18, tailwindcss ≥ 4
Added
13 Oct 2026
Updated
—

02Usage

The default configuration. Change properties above to generate a tailored example in the Usage tab.

example.tsx
import { MaskedText } from "@/components/ui/masked-text";

export function MaskedTextExample() {
  return (
    <MaskedText className="text-6xl leading-none sm:text-8xl">
      Made with intent
    </MaskedText>
  );
}

03Props

PropTypeDefaultDescription
childrenReactNode—The text to mask. Keep it plain text — it stays selectable and accessible.
as"h1" | "h2" | "h3" | "p" | "span" | "div""h2"Element to render.
mode"gradient" | "noise" | "stripes" | "image""gradient"Texture shown through the letterforms.
srcstring—Image URL for mode="image"; without it the gradient is used.
accentstring"#FF7448"First texture colour.
secondarystring"#B6F3D1"Second texture colour.
speednumber1Drift speed multiplier (≈40px/s at 1); 0 keeps the texture still.
anglenumber100Gradient angle in degrees (gradient and grain modes).
parallaxnumber24How far the texture follows a fine pointer, in px; 0 disables it.
...propsHTMLAttributes—Forwarded to the root element.

04Features

  • 01background-clip: text over four textures: moving gradient, grain, stripes, image
  • 02Seamless loops: the gradient is periodic at 200% width, stripes tile on a fixed grid
  • 03Pointer parallax on fine pointers, eased in one rAF loop
  • 04Loop pauses offscreen and in hidden tabs; stops entirely when still
  • 05Ink colour follows the light/dark theme; accent colours are props
motion · continuousinput · pointer

05Accessibility

  • The text is a real heading (or the element you choose): selectable, searchable and read normally by screen readers.
  • Where background-clip: text is unsupported the texture is not painted and the text falls back to a solid ink colour; forced-colours mode does the same.
  • Selected text gets a solid accent background so the selection stays legible.
  • With prefers-reduced-motion the texture does not drift or follow the pointer.
  • On light pages the secondary colour is mixed 40% towards the ink so pale tints stay legible; still check contrast for your own colours and keep the type large.

06Limitations

  • Textures are only visible on the glyphs, so thin weights show little of them; use bold display sizes.
  • Image mode needs an image that also reads at the scale of the letters; the image is scaled to 130% of the text width.