Components

Scratch to Reveal

A scratch card component for React and Tailwind CSS: visitors scratch a canvas foil with a mouse, pen or finger to uncover a coupon, prize or secret, and the rest dissolves once enough is gone. Sharp on retina screens, with a real Reveal button for keyboard and screen reader users.

  • Canvas foil
  • Mouse, pen & touch
  • onComplete callback
  • Keyboard alternative
  • High-DPI

You unlocked

25% off

DUSK-25

Scratch at least 45% of the foil.

Installation

$ npx shadcn@latest add https://duskui.com/r/scratch-to-reveal.json

Usage

coupon.tsx
"use client"

import { ScratchToReveal } from "@/components/dusk/scratch-to-reveal/scratch-to-reveal"

export function Coupon() {
  return (
    <ScratchToReveal
      className="h-40 w-72"
      minScratchPercentage={50}
      onComplete={() => console.log("revealed")}
    >
      <div className="grid size-full place-items-center bg-card text-2xl font-bold">
        FREE SHIPPING
      </div>
    </ScratchToReveal>
  )
}

Examples

Custom foil

Pass any CSS colors to gradientColors for the foil; pattern adds a fine hatch and glints. showRevealButton keeps the Reveal button visible for everyone.

Admit one

Row F, Seat 12

Sat 21:00 · Hall B

Brush & threshold

A smaller brushSize and a lower minScratchPercentage suit small tiles. hint={null} hides the overlay label.

Lucky
Star
Lucky

Small brush, 30% threshold

API Reference

Also accepts any HTML attribute for the wrapper. It fills the size you give it with className (or the size of its content).

PropTypeDefaultDescription
childrenReactNode—The hidden content.
brushSizenumber22Brush radius in CSS px.
minScratchPercentagenumber50Percentage of the foil (0–100) to scratch before the rest dissolves.
onComplete() => void—Called once when fully revealed, by scratching or by the button.
gradientColorsstring[]silver foilTwo or more CSS colors for the diagonal foil gradient.
patternbooleantrueOverlay a fine hatch and glints on the foil.
hintReactNode | null"Scratch to reveal"Label over the foil until scratching starts. null hides it.
revealLabelstring"Reveal"Text of the reveal button.
showRevealButtonbooleanfalseKeep the reveal button visible. By default it appears on keyboard focus.
aria-labelstring"Scratch card"Accessible name of the card group.

Accessibility

  • A real Reveal button sits in the tab order and appears when focused; activating it reveals the content and moves focus to it.
  • The hidden content is inert until revealed, so it is neither focusable nor announced early, but it is in the HTML from the start.
  • The canvas and hint are aria-hidden decorations; a CSS copy of the foil covers the content in server HTML so it never flashes before hydration.
  • The reveal animation is instant with prefers-reduced-motion.
  • touch-action: none applies only to the foil, so the page scrolls normally once the card is revealed.