Media and files
Signature pad
Smooth, speed and pressure aware strokes with pen colors and width, undo, clear, PNG and SVG export, and strokes that survive a resize; the result goes into a hidden input. A typed name field stays available for people who cannot draw. It needs monsoon.js. Without it only the typed name field shows.
Needs monsoon.js. The styles work on their own, and the behavior comes from the optional interactive layer: add <script src="https://cdn.jsdelivr.net/npm/monsooncss/dist/monsoon.js" defer></script> or import 'monsooncss/js'. See the interactive layer.
Example
<div class="signature max-w-lg" data-m-signature><input type="hidden" name="signature"><label class="grid gap-1 text-sm"><span class="text-muted-foreground">Or type your full name</span><input class="input signature-fallback" name="signature_name" autocomplete="name"></label></div>JavaScript API
Attribute
data-m-signature on a .signature; the pad, canvas and toolbar are created when missing
Options
| Option | Description |
|---|---|
data-m-signature-colors | Comma list of pen colors, CSS colors or tokens, var(--foreground),var(--primary),var(--info) by default. |
data-m-signature-width | Pen width in pixels, 2.5 by default. |
data-m-signature-format | png (default) or svg, for the hidden input value. |
data-m-signature-input | Selector of the hidden input, defaults to one inside. |
data-m-signature-placeholder | Text on the empty pad, Sign here by default. |
data-m-signature-toolbar | false hides the toolbar. |
Methods
| Method | Description |
|---|---|
Monsoon.signature(el).toDataURL(type, quality, options) | PNG by default. options: { scale, background }. |
Monsoon.signature(el).toBlob(type, quality, options) | Promise of a Blob. |
Monsoon.signature(el).toSVG(options) | SVG markup string with one path per segment. |
Monsoon.signature(el).toData() and fromData(strokes) | Saves and restores the strokes. |
Monsoon.signature(el).undo() and clear() | Removes the last or every stroke. |
Monsoon.signature(el).setColor(color) and setWidth(px) | Changes the pen. |
Monsoon.signature(el).empty | True when nothing is drawn. |
Events
| Event | Description |
|---|---|
monsoon:signature-change | detail.empty and detail.strokes after each stroke, undo or clear. |
Keyboard
Ctrl or Cmd and Z undoes while the pad has focus.
Classes
10 classes. Click a name to copy it. Utilities on the same element always win over component defaults, so any of them can be adjusted with plain utility classes.
| Class | Type | What it does |
|---|---|---|
| Base | Base class of the signature pad. On a <div> in the example. Sets grid display, gap, width, hidden by default and opacity, and --tone.CSS |
|
| Modifier | Modifier, combined with the signature class. Not used in the example above. Sets height, overflow, border, corner radius, background and shadow.CSS |
|
| Modifier | Modifier, combined with the signature class. Not used in the example above. Sets block display, width, height, border and crosshair cursor.CSS |
|
| Modifier | Modifier, combined with the signature class. Not used in the example above. Sets absolute position, offsets, text color, text size, transition and generated content.CSS |
|
| Modifier | Modifier, combined with the signature class. Not used in the example above. Sets flex display, alignment and gap.CSS |
|
| Modifier | Modifier, combined with the signature class. Not used in the example above. Sets flex display and gap.CSS |
|
| Modifier | Modifier, combined with the signature class. Not used in the example above. Sets width, height, padding, border, corner radius and background.CSS |
|
| Modifier | Modifier, combined with the signature class. Not used in the example above. Sets alignment and width.CSS |
|
| Modifier | Modifier, combined with the signature class. Not used in the example above. Sets flex display, gap and margin.CSS |
|
| Part | Part of the signature pad. On an <input> in the example. Sets width.CSS |
Usage
The styles ship inside the same stylesheet as the utilities, and the behavior comes from the optional monsoon.js script, which enhances any element with a matching data-m attribute, including markup added later.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/monsooncss">
<script src="https://cdn.jsdelivr.net/npm/monsooncss/dist/monsoon.js" defer></script>
<!-- Signature pad: start from the base class, then add modifiers -->
<div class="signature max-w-lg" data-m-signature><input type="hidden" name="signature"><label class="grid gap-1 text-sm"><span class="text-muted-foreground">Or type your full name</span><input class="input signature-fallback" name="signature_name" autocomplete="name"></label></div>Theme it with --seed on any ancestor, for example style="--seed: #0d9488", and force a scheme with class="dark" or class="light" on a wrapper.
Accessibility
- Give every control a visible
labellinked withfor, or anaria-labelwhen the purpose is obvious from context. Link help and error text witharia-describedby; invalid styles use:user-invalid, so they appear only after the user interacts. - Every interactive part shows a visible focus ring with
:focus-visible, and tone colors pair with-foregroundtokens that keep text at 4.5:1 or better in light and dark mode.