Scratch To Reveal
MotionReact scratch card with a gradient foil you rub away by pointer or touch to show the content beneath, clearing itself once past a set threshold.
Installation
npx shadcn@latest add @minidev/scratch-to-reveal
MiniDev UI is in the shadcn registry directory, so the short form works with no setup. Older CLI versions can use the full URL: npx shadcn@latest add https://ui.minidev.pro/r/scratch-to-reveal.json
Usage
import { ScratchToReveal } from "@/components/ui/scratch-to-reveal"
export function Example() {
return (
<ScratchToReveal />
)
}
API reference
| Prop | Type | Default |
|---|---|---|
| thresholdPercent of the foil that must be scratched before the rest clears itself. | number | 50 |
| brushBrush radius in pixels. | number | 24 |
| gradientColours of the foil gradient. CSS colours and var(--token) both work. | string[] | DEFAULT_GRADIENT |
| labelHint printed on the foil. | string | "Scratch to reveal" |
| onCompleteCalled once the card is fully revealed. | () => void | - |
| onProgressCalled with the scratched percentage as it changes. | (percent: number) => void | - |
| children | React.ReactNode | - |
| className | string | - |
When to use
Use it for a playful reward, promo code or launch teaser. Reach for SecretReveal to show a sensitive value behind a click, and BeforeAfterWipe to compare two images.
Keyboard interactions
| Key | Action |
|---|---|
| Tab | Focuses the Reveal button in the bottom-right corner of the foil. |
| EnterorSpace | On Reveal, clears the foil and moves focus to the revealed content. |
Accessibility
- Until revealed, the content is
aria-hiddenandinert, so neither screen readers nor Tab reach it. - A Reveal button gives keyboard and switch users the same result as scratching. Focus moves to the content after it.
- An
sr-onlyrole="status"region announces "Revealed." - Under reduced motion the foil disappears at once instead of fading out.
Frequently asked questions
Is the hidden content secret?
No. The children are in the DOM and the server HTML from the start, only aria-hidden and inert until revealed. Do not put a single-use code there that people must not see; fetch it in onComplete instead.
How do I know when the card is revealed?
onComplete fires exactly once, when the scratched share reaches threshold (default 50%) or the Reveal button is pressed. onProgress receives the scratched percentage as it changes.
Does scratching work on phones?
Yes. The foil canvas uses pointer events with pointer capture and touch-action: none, so a finger scratches instead of scrolling the page while it is on the card.
Dependencies
npm
Built from
Examples
Your own prize
Children are what the foil hides; gradient takes any CSS colours or tokens and label is the hint printed on top.
Progress and completion
onProgress reports the scratched percent as it changes and onComplete fires once, when the rest of the foil clears itself.
Big brush, low threshold
A wide brush and a 30 percent threshold make one or two swipes enough, for a card that should not feel like work.