Micro-interactions

Scratch

A scratch-off card. Drag over the foil to scrape it off, and small flakes fall where you scratch. Once enough foil is gone, the rest fades away on its own. A light glints across the foil now and then. You can also focus the card and press Enter or Space to reveal it.

Install

# Scratch needs no npm packages

Then copy 2 files into your project:

  • components/registry/scratch/scratch.tsx
  • hooks/use-animation-loop.ts

Props

PropTypeDefaultDescription
brushSizenumber34Width of the scratch.
thresholdnumber55How much foil has to come off before the rest falls away.
revealDurationnumber450How long the leftover foil takes to fade out.
flakesbooleantrueFoil flakes fall from where you scratch.
glintbooleantrueA light sweeps across the foil now and then.
glintColorstring (hex)"#a855f7"The light that sweeps across the foil. The focus ring uses it too.
foilColorstring (hex)"#c9c3d6"The foil. Its flakes take their color from it.

What It Demonstrates

Reveal
Content is uncovered gradually, often by animating a clip-path or mask.
Mask
Hiding or revealing parts of an element using a shape or gradient — like clip-path, but with soft, fadeable edges.
Drag
Moving an element by grabbing it, often with momentum when released.
Fade in / Fade out
Element appears or disappears by changing opacity.

Related Components

Appears In