Skip to content
VenusUI
Get started

Scratch Card

A scratch-off card: scratch the silver coating with a mouse or finger to reveal what's underneath.

Preview

Installation

npx shadcn@latest add @venusui/scratch-card

Run this in a project set up with shadcn. If you haven’t set it up yet, run npx shadcn@latest init first.

Files added to your project

Paths use the default shadcn aliases. The CLI follows the aliases in your components.json.

  • @/components/ui/scratch-card.tsx

Usage

The code behind the preview above.

scratch-card-demo.tsx

import { ScratchCard } from "@/components/ui/scratch-card"

export default function ScratchCardDemo() {
  return (
    <ScratchCard className="w-[min(22rem,calc(100vw-3rem))]">
      <div className="flex aspect-[16/9] flex-col items-center justify-center gap-1 bg-linear-to-br from-amber-100 via-rose-100 to-violet-100 p-6 text-center text-neutral-900">
        <p className="text-xs font-semibold tracking-[0.2em] text-rose-600 uppercase">You won</p>
        <p className="text-4xl font-bold tracking-tight">Free shipping</p>
        <p className="font-mono text-sm tracking-widest">SHIPFREE26</p>
      </div>
    </ScratchCard>
  )
}

API reference

PropTypeDefaultDescription
childrenReactNode—What's under the coating.
thresholdnumber0.55Share of the coating to scratch off before it clears completely.
brushnumber22Scratch radius in px.
labelstring"Scratch here"Printed on the coating.
onReveal() => void—Called once when the content is revealed.

All <div> props except children.

Requirements

  • React 19 and Tailwind CSS v4. Uses a canvas; no libraries.

Customization

  • Change the coating colors in the gradient in paint(). A gold coating (#fde68a to #d97706) works well for prizes.

Accessibility

  • The hidden content is inert until revealed; a button reveals it without scratching.
  • The reveal is announced (“Revealed!”).

Troubleshooting

Scratching scrolls the page on a phone.
The canvas uses touch-none; make sure nothing above it captures the touch.
Unknown registry "@venusui"
Your shadcn CLI couldn’t find the namespace in the shadcn registry index. Use the latest CLI (npx shadcn@latest), install by URL, or register it with its address: npx shadcn@latest registry add @venusui=https://venusui.com/r/{name}.json.
No components.json found
Run npx shadcn@latest init in your project first.
Loading preview

A card that tilts in 3D toward the pointer with spring physics.

Loading preview

A flight boarding pass with a perforated stub and code that flips to the fare and baggage details.

Loading preview

Stacked cards with the next ones peeking out; Next sends the top card to the back.