---
title: "Scratch Card"
description: "A card with a foil that people scratch off with a finger or a mouse to show a prize. Enter or Space plays a scratch and shows it."
url: https://gelatinui.com/components/scratch-card
markdown_url: https://gelatinui.com/components/scratch-card.md
access: pro
install: "npx shadcn@latest add @gelatin-ui-pro/scratch-card"
version: "2026-11-09"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Scratch Card

> A card with a foil that people scratch off with a finger or a mouse to show a prize. Enter or Space plays a scratch and shows it.

Page: https://gelatinui.com/components/scratch-card

## When to use it

Best for: A reward, a prize, or a coupon code that people show by hand, as a small game.

- Put the prize in `ScratchCardContent` and the label in `ScratchCardFoil`, both inside `ScratchCardSurface`.
- Put `ScratchCardKeyHint` in the foil to show "Press Enter to reveal" while the foil has keyboard focus.
- Lower `threshold` and raise `brushSize` for a small card on a phone.
- Read `onRevealedChange` to save that the prize was seen, and pass `revealed` to keep it open next time.

## When not to use it

- For text that people only must click to show, use a [Spoiler](https://gelatinui.com/components/spoiler.md).
- For a password or a key that people show and hide, use a [Password Field](https://gelatinui.com/components/password-field.md).

## Notes for agents

- The foil is a Base UI `Button`: Enter, Space, and a screen reader click play a scratch sweep and reveal.
- `foil` is `hatch` (default), `metallic`, or `holographic`. The canvas paints it from the theme tokens.
- Past `threshold` (default 0.6, from 0.2 to 1) the rest of the foil falls away.
- The content is `inert` until the reveal. After a key reveal it takes the focus.
- Use `useScratchCardActor` with `ScratchCardRootProvider` to reveal or reset the card from the app.
- `ScratchCardFoil` takes `driverRef` (a `DragDriver`): a staged scene or a test scratches from code with `pickUp`, `carry`, and `drop` at viewport points, and no pointer event is sent.

## Anatomy

```text
ScratchCard
├─ ScratchCardRootProvider (0..n)
├─ ScratchCardSurface (0..n)
├─ ScratchCardContent (0..n)
├─ ScratchCardFoil (0..n)
├─ ScratchCardLabel (0..n)
├─ ScratchCardKeyHint (0..n)
└─ ScratchCardDescription (0..n)
```

## API reference

### ScratchCard

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` |  |  |
| `foil` | `ScratchCardFoilLook` |  | The look of the foil: `hatch` (default, diagonal lines), `metallic`, or `holographic`. |
| `threshold` | `number` |  | The scratched share (0.2 to 1) past which the rest of the foil falls away. Default 0.6. |
| `brushSize` | `number` |  | The brush width in CSS px. Default 32. |
| `revealed` | `boolean` |  | The content shows (controlled). |
| `defaultRevealed` | `boolean` |  | The content shows at first (uncontrolled). |
| `onRevealedChange` | `function` |  | Called when the reveal starts (`true`) and after a reset (`false`). |
| `disabled` | `boolean` |  | No scratch and no key reveal. |

### ScratchCardSurface

No props of its own: `className`, `children`, and every other prop go to the element it renders.

### ScratchCardContent

No props of its own: `className`, `children`, and every other prop go to the element it renders.

### ScratchCardFoil

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `driverRef` | `Ref<DragDriver \| null>` |  | Drives a scratch from code (`DragDriver`, no item): a staged scene or a test presses the foil at a viewport point, carries the brush, and lets go. The cuts, the dust, and the reveal work as for a finger, and no pointer event is sent. |

Also takes every prop of Base UI `Button`: https://base-ui.com/react/components/button

### ScratchCardLabel

No props of its own: `className`, `children`, and every other prop go to the element it renders.

### ScratchCardKeyHint

No props of its own: `className`, `children`, and every other prop go to the element it renders.

### ScratchCardDescription

No props of its own: `className`, `children`, and every other prop go to the element it renders.

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| ScratchCard | `scratch-card` |  |  |  |
| ScratchCardRootProvider | `scratch-card` |  |  |  |
| ScratchCardSurface | `scratch-card-surface` | `data-disabled`, `data-stage-focused`, `data-stage-hover` |  | `motion-timing` |
| ScratchCardContent | `scratch-card-content` |  | `--scratch-card-scale` |  |
| ScratchCardFoil | `scratch-card-foil` | `data-disabled`, `data-painted` | `--foreground`, `--scratch-card-brush`, `--scratch-card-foil`, `--scratch-card-metal-from`, `--scratch-card-metal-mid`, `--scratch-card-metal-to`, `--scratch-card-opacity`, `--scratch-card-scale`, `--scratch-card-sheen`, `--scratch-card-stripe`, `--scratch-card-x`, `--scratch-card-y` |  |
| ScratchCardLabel | `scratch-card-label` |  | `--scratch-card-opacity` |  |
| ScratchCardKeyHint | `scratch-card-key-hint` |  |  |  |
| ScratchCardDescription | `scratch-card-description` |  |  |  |

## Usage

Put the prize and the foil inside `ScratchCardSurface`. The label names the foil.

```tsx title="reward-card.tsx"
import {
  ScratchCard, ScratchCardContent, ScratchCardDescription,
  ScratchCardFoil, ScratchCardKeyHint, ScratchCardLabel, ScratchCardSurface,
} from "@/components/pro/effects/scratch-card";

export function RewardCard() {
  return (
    <ScratchCard className="w-72">
      <ScratchCardSurface>
        <ScratchCardContent>
          <p className="text-3xl font-semibold">$5.00</p>
          <p className="text-sm text-muted-foreground">Cashback on your next order</p>
        </ScratchCardContent>
        <ScratchCardFoil>
          <ScratchCardLabel>Scratch to reveal</ScratchCardLabel>
          <ScratchCardKeyHint />
        </ScratchCardFoil>
      </ScratchCardSurface>
      <ScratchCardDescription>Drag across the card to scratch off the foil.</ScratchCardDescription>
    </ScratchCard>
  );
}
```

## Compose

Rules:

- Compose the parts (`compose-parts`): Build each item from its named parts as children, and pass your text and icons in as parts.
- Every state is designed (`every-state`): Give each view of data its loading, empty, and error states: a skeleton in the final layout, an `Empty` with an illustration and one next action, and an error that says what failed and how to retry.

## Add it

```bash
npx shadcn@latest add @gelatin-ui-pro/scratch-card
```

It adds 34 registry items: 33 files, 5623 lines, and the npm packages `@base-ui/react`, `@mantine/hooks`, `@xstate/react`, `clsx`, `motion`, `tailwind-merge`, `xstate`.

## For AI agents

- Every item, one file: https://gelatinui.com/llms.txt
- MCP server (`search_items`, `get_item`, `get_install_plan`): https://gelatinui.com/mcp

## Related

- [Spoiler](https://gelatinui.com/components/spoiler.md)
- [Card](https://gelatinui.com/components/card.md)
- [Button](https://gelatinui.com/components/button.md)
- [Copy Button](https://gelatinui.com/components/copy-button.md)

## Keyboard

| Keys | Action |
| --- | --- |
| Tab | Moves to the foil. The `ScratchCardKeyHint` shows under the label. |
| Enter | Plays a scratch sweep and shows the prize. The focus goes to the prize. |
| Space | Plays a scratch sweep and shows the prize. The focus goes to the prize. |

## Accessibility

The foil is a Base UI `Button` named by `ScratchCardLabel` and described by `ScratchCardDescription`. A screen reader click plays the sweep and shows the prize.

Until the reveal, the content is `inert` and `aria-hidden`, so no one reads or tabs into the prize. After a key reveal, the content takes the focus, so the focus never drops to the page.

A disabled card is dimmed and the foil is not a tab stop.

The foil sets `touch-action: none`, so a finger scratches and does not scroll the page. The brush ring shows only for a mouse or a pen.

## Motion

| Part | Motion |
| --- | --- |
| Key sweep | sheet · 600ms · ease-panel (0.2, 0.4, 0.2, 1), a brush crosses the card in three lines |
| Foil falls away | overlay · 200ms · the foil fades and grows, with a burst of dust |
| Prize | popup · 150ms · the prize grows from 96% to 100% |
| Label | fade-exit · 90ms · the label fades when the scratch starts |
