Forms

Signature pad

Sign with a finger, pen or mouse: the ink thins as it speeds up, and a pen's pressure is felt. Anyone who can't draw can type their name instead.

Installation

npx sinaui add signature-pad

Examples

Signing for a loan

Draw above the line. Undo takes back the last stroke; Clear starts again.

Loan of the Canon of Medicine Bayt al-Hikma, Baghdad · returned within 40 days
Maryam al-Asturlabi

Nothing signed yet.

Not signed yet.

<script lang="ts">
	import SignaturePad from '#lib/ui/SignaturePad.svelte';

	let empty = $state(true);
</script>

<div class="demo">
	<div class="terms">
		<strong>Loan of the Canon of Medicine</strong>
		<span>Bayt al-Hikma, Baghdad · returned within 40 days</span>
	</div>
	<SignaturePad label="Borrower's signature" signer="Maryam al-Asturlabi" bind:empty />
	<p class="status" role="status">{empty ? 'Not signed yet.' : 'Signed. Ready to borrow.'}</p>
</div>

<style>
	.demo {
		display: grid;
		gap: 0.75rem;
		inline-size: min(28rem, 100%);
	}
	.terms {
		display: grid;
	}
	.terms span,
	.status {
		margin: 0;
		color: var(--ui-muted);
		font-size: 0.875rem;
	}
</style>

In a form

With a name, the signature posts as a PNG data URL. toSVG() gives the strokes as SVG.

Thābit ibn Qurra

Nothing signed yet.

<script lang="ts">
	import Button from '#lib/ui/Button.svelte';
	import SignaturePad from '#lib/ui/SignaturePad.svelte';

	let pad = $state<SignaturePad>();
	let empty = $state(true);
	let result = $state('');
	let tried = $state(false);

	function submit(e: SubmitEvent) {
		e.preventDefault();
		tried = true;
		if (empty) return;
		const svg = pad?.toSVG() ?? '';
		result = svg
			? `Sent as SVG (${new Intl.NumberFormat().format(svg.length)} characters) and PNG.`
			: 'Sent as PNG.';
	}
</script>

<form class="demo" onsubmit={submit} novalidate>
	<SignaturePad
		bind:this={pad}
		bind:empty
		label="Witness"
		signer="Thābit ibn Qurra"
		name="witness"
	/>
	{#if tried && empty}<p class="error">Sign above, or type your name instead.</p>{/if}
	<Button type="submit">Witness the copy</Button>
	<p class="status" role="status">{result}</p>
</form>

<style>
	.demo {
		display: grid;
		justify-items: start;
		gap: 0.75rem;
		inline-size: min(28rem, 100%);
	}
	.demo > :global(.signature) {
		justify-self: stretch;
	}
	.error,
	.status {
		margin: 0;
		font-size: 0.875rem;
	}
	.error {
		color: var(--ui-danger);
	}
	.status {
		color: var(--ui-muted);
	}
</style>

Props

PropTypeDefault
labelstring'Signature'
signerstring: printed under the line
valuestring: a PNG data URL (bindable)''
emptyboolean (bindable)true
namestring: posts the PNG with a form

Bind the component to call toSVG() or toPNG(); both return '' when it's empty.

Keyboard

KeyDoes
⌘ Z / Ctrl ZUndo the last stroke
TabReach "Type instead", Undo and Clear

Accessibility

  • "Type instead" swaps drawing for a name field, so it can be signed from the keyboard.
  • Whether it's signed is read out as it changes.
  • The ink follows the text color, so it stays readable in dark mode.
Introduction
Theming
Changelog
Button
Action button
Confirm button
Copy button
Hold to confirm
Split button
Calendar
Checkbox
Color picker
Combobox
Date picker
Date range picker
File drop
Form
Input
Mention input
Multi select
Number field
OTP input
Password input
Phone input
Radio cards
Radio group
Rich text editor
Search field
Segmented control
Select
Signature pad
Slider
Switch
Tag input
Upload
Wheel picker
Textarea
Time field
Toggle group
Toolbar
Alert dialog
Command palette
Context menu
Dialog
Drawer
Dropdown
Hover card
Popover
Tooltip
Announcement bar
Alert
Empty state
Meter
Progress
Rolling number
Skeleton
Spinner
Toast
Avatar
Avatar group
Badge
Card
Carousel
Chart
Chat
Code block
Data table
Folder
Kbd
Mind map
Resizable panels
Scroll area
Separator
Sortable
Table
Tag group
Virtual list
Audio player
Image
Image compare
Video
Visualizer
Breadcrumb
File tree
Menubar
Navigation menu
Pagination
Sidebar layout
Stepper
Tabs
Alarm clock
Clock
Dynamic island
Fluid orb
Hourglass
Stopwatch
Timer
AI chat
AI media
Auth
Board
Booking
Dashboard
File explorer
Messaging
Notifications
Settings
Team
Overview
Pricing
Agent chat
Calendar
Voice agent
Mail inbox
CMS
Blog
Marketing site
E-commerce
AI agents
SaaS landing page
SaaS app
Accordion
Dark theme
Light theme