Code

<!-- scratch-reveal.free.js: download it from the Install section below and host it with your site -->
<script src="/scratch-reveal.free.js" defer></script>

<scratch-reveal label="Scratch to reveal" brush="38" threshold="0.55" radius="20" theme="light" style="width: 320px">
  <div class="prize">
    <small>Your welcome gift</small>
    <strong>25% off</strong>
    <code>PEARL25</code>
  </div>
</scratch-reveal>

<script>
  const card = document.querySelector('scratch-reveal');
  card.addEventListener('reveal', () => console.log('revealed'));
  card.addEventListener('progress', (e) => console.log(e.detail.value)); // 0..1
  // card.reset(); card.reveal(); card.scratchLine(0.1, 0.5, 0.9, 0.5);
</script>

In context

Daily reward
Sunset foil, a promo code Pro

Install · Free Web Component

One file, no dependencies. Aurora preset, every other option included. Host it yourself so your visitors never load anything from our servers.

1. Install with one command — or download the file
shadcn CLI · React
npx shadcn@latest add https://www.ui-design.co/r/scratch-reveal.json
2. Load it and use the element
HTML
<!-- scratch-reveal.free.js: download it from the Install section below and host it with your site -->
<script src="/scratch-reveal.free.js" defer></script>

<scratch-reveal label="Scratch to reveal" brush="38" threshold="0.55" radius="20" theme="light" style="width: 320px">
  <div class="prize">
    <small>Your welcome gift</small>
    <strong>25% off</strong>
    <code>PEARL25</code>
  </div>
</scratch-reveal>

<script>
  const card = document.querySelector('scratch-reveal');
  card.addEventListener('reveal', () => console.log('revealed'));
  card.addEventListener('progress', (e) => console.log(e.detail.value)); // 0..1
  // card.reset(); card.reveal(); card.scratchLine(0.1, 0.5, 0.9, 0.5);
</script>
3. React + TypeScript (optional)

The shadcn command adds a typed React wrapper for you. Using the file directly? Custom elements work in React as-is; for type checking add:

TypeScript
// scratch-reveal.d.ts
declare namespace JSX {
  interface IntrinsicElements {
    'scratch-reveal': React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement> & {
      brush?: number | string;
      threshold?: number | string;
      radius?: number | string;
      label?: string;
      revealed?: boolean | '';
      theme?: 'light' | 'dark';
      sound?: boolean | '';
    };
  }
}

Pro · React + TypeScript Pro

One payment of $4.99, yours forever. Use it in unlimited personal and commercial projects; no resale.

  • React component that covers any node, with a ref for reset, reveal and scratchLine, TypeScript types and the full source
  • Sunset, Mint and Mono foils, plus custom foils from Brand Fit
  • The vanilla Web Component with every foil, a demo page, README and license

Attributes & props

NameTypeDefaultDescription
children any content—What is under the foil. The card takes its size from the content, or set a width / height on the element.
brush number (px)38Diameter of the brush. The cursor is a ring of the same size.
threshold 0..10.55Share of the area that has to be cleared before the rest dissolves and reveal fires.
label string'Scratch to reveal'Hint pressed into the foil; also the accessible name. An empty string draws nothing.
radius number (px)20Corner radius of the card.
revealed booleanfalseForces the content open (for example for someone who already claimed the prize); removing it puts the foil back.
theme 'light' | 'dark''light'A bright pearl foil or a dark graphite one.
sound booleanoffFine ticks while scratching and a glass chime on reveal. Also on for everything inside an element with data-ui-sound="on".
reveal / progress events—reveal fires once when the card opens; progress fires while scratching with detail.value from 0 to 1.
reset() / reveal() / scratchLine(x0, y0, x1, y1) methods—Put the foil back, open the card, or scratch a line from script (coordinates are 0..1 of the width and height).
tint Pro'aurora' | 'sunset' | 'mint' | 'mono' | object'aurora'Colours of the foil and of the falling flakes, or a custom tint. Free build ships Aurora only.

The foil is drawn in code on a canvas: a pearl body, three pools of colour from the tint, an engraved weave, grain and glitter, so there is nothing to download and it stays sharp on any screen. Scratches are kept in a separate mask, which lets the card resize or change theme without losing them. Until it opens the card is one focusable button (Enter or Space reveals it) and the content is hidden from assistive technology and from Tab. Only the foil has touch-action: none, so the page still scrolls from anywhere else. The foil hides the content visually, not in the page source: do not treat it as a secret. With reduced motion there are no flakes and the foil fades out. No WebGL.

More components