WebberUI

Signature Pad

Handwritten signatures on canvas: pressure-sensitive stroke width, clear and redraw, export to PNG.

A handwritten signature pad built with canvas 2d and Pointer Events: the line width changes live with writing speed (or with a stylus's real pressure) to imitate a fountain pen. Strokes are kept on a stack, supporting stroke-by-stroke undo, one-click clear, and PNG download, plus a dashed signature baseline and a "please sign" watermark.

Loading preview…
npx shadcn@latest add https://webberui.com/r/signature-pad.json

Playground

Tune the props live — the code snippet updates as you go, so you can dial in the look you want before copying it.

1.5
4
220
<SignaturePad />

Installation

npx shadcn@latest add https://webberui.com/r/signature-pad.json

Or, once registries are configured in components.json, install it as @webberui/signature-pad.

Usage

import { SignaturePad } from "@/components/ui/signature-pad";

<SignaturePad
  height={200}
  onChange={(dataUrl) => {
    // dataUrl is a PNG dataURL, or null when the canvas is empty
    console.log(dataUrl);
  }}
/>

Props

PropTypeDefaultDescription
strokeColorstring"currentColor"Ink colour; by default it reads the container's text colour at the moment the stroke starts, adapting to light and dark themes automatically
minWidthnumber1.5Thinnest line width during a fast stroke (px)
maxWidthnumber4Thickest line width during a slow stroke (px)
heightnumber220Height of the signature area (px); the width fills the container automatically
placeholderstring"請簽名"Watermark text shown before any stroke is drawn
fileNamestring"signature"File name for the PNG download (without the extension)
exportBackgroundstring"#ffffff"Background colour of the exported PNG; set "transparent" to output a transparent background
onChange(dataUrl: string | null) => voidCallback after every stroke ends, undo, or clear; passes null when the canvas is empty
classNamestringForwarded to the outermost container

Accessibility

  • The signature area carries role="img" and aria-label="手寫簽名區", and the toolbar buttons are native buttons with text labels and a disabled state
  • It uses Pointer Events with touch-action: none, so mouse, finger, and stylus all write; a stylus uses its real pressure values
  • When the user has "reduce motion" enabled at the system level, the watermark transition and the button micro-scale animation are disabled, while the writing functionality is completely unaffected
  • A handwritten signature inherently requires a pointing device; in a production form, please also offer an alternative way to consent (for example a checkbox plus a typed name)

On this page