---
title: "Signature Pad · Ark UI — StyleX Blocks"
description: "Freehand drawing surface for signatures with smooth pressure-aware strokes, a guide line, a clear button, and a hidden input for forms."
url: "https://stylexblocks.com/components/ark-ui/signature-pad/"
agent:
  instructions: "Use this search API to find relevant components and blocks across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://stylexblocks.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Signature Pad

Freehand drawing surface for signatures with smooth pressure-aware strokes, a guide line, a clear button, and a hidden input for forms.

- Behavior engine: Ark UI
- Also available for: [Base UI](https://stylexblocks.com/components/base-ui/signature-pad.md), [UI SDK](https://stylexblocks.com/components/ui-sdk/signature-pad.md)
- Category: Form
- Variants: outline, subtle
- Sizes: sm, md, lg
- HTML page: https://stylexblocks.com/components/ark-ui/signature-pad/

## Install

Configure the project once (sets the behavior engine and import aliases):

```sh
npx stylexblocks init
```

Then add the item as source you own:

```sh
npx stylexblocks add signature-pad
```

Equivalent: `npx shadcn add @stylexblocks/signature-pad`. Registry item JSON: https://stylexblocks.com/r/ark-ui/signature-pad.json

## Usage

```tsx
import { SignaturePad } from "#components/ui/ark-ui/signature-pad.tsx";

export function Example() {
  return (
    // variant/size resolve once on Root. Ink is filled with currentColor
    // (semantic fg), so it follows dark mode. ClearTrigger ships a default
    // icon and hides while the pad is empty; HiddenInput carries an SVG data
    // URL of the strokes into form submissions.
    <SignaturePad.Root name="signature" variant="outline" size="md">
      <SignaturePad.Label>Sign here</SignaturePad.Label>
      <SignaturePad.Control>
        <SignaturePad.Segment />
        <SignaturePad.Guide />
        <SignaturePad.ClearTrigger />
      </SignaturePad.Control>
      <SignaturePad.HiddenInput />
    </SignaturePad.Root>
  );
}

// export: onDrawEnd={(d) => d.getDataUrl("image/png").then(upload)}
// pen: drawing={{ size: 4, thinning: 0.6, simulatePressure: false }}
```

## Examples

### In a form

HiddenInput submits the signature as an SVG data URL under the Root's `name`; the line below shows its current value.

```tsx
<SignaturePad.Root name="signature">
  <SignaturePad.Label>Sign to accept</SignaturePad.Label>
  <SignaturePad.Control>
    <SignaturePad.Segment />
    <SignaturePad.Guide />
    <SignaturePad.ClearTrigger />
  </SignaturePad.Control>
  {/* submits an SVG data URL under "signature" */}
  <SignaturePad.HiddenInput />
</SignaturePad.Root>
```

## Source

`components/ui/ark-ui/signature-pad.tsx`

```tsx
import * as stylex from "@stylexjs/stylex";
import { useEffect, useState } from "react";
import {
  SignaturePad as ArkSignaturePad,
  useSignaturePadContext,
} from "@ark-ui/react/signature-pad";
import { createSlotRecipeContext } from "#lib/ark-ui/create-slot-recipe-context.tsx";
import { defineSlotRecipe, resolveSlotStyles } from "#lib/recipe-props.ts";
import { colorPalette } from '@stylexblocks/ui/color-palette.stylex.ts'
import { fontSizes } from '@stylexblocks/ui/tokens/font-sizes.stylex.ts'
import { fontWeights } from '@stylexblocks/ui/tokens/font-weights.stylex.ts'
import { lineHeights } from '@stylexblocks/ui/tokens/line-heights.stylex.ts'
import { semanticColors } from '@stylexblocks/ui/semantic-tokens/colors.stylex.ts'
import { semanticRadii } from '@stylexblocks/ui/semantic-tokens/radii.stylex.ts'
import { sizes } from '@stylexblocks/ui/tokens/sizes.stylex.ts'
import { spacing } from '@stylexblocks/ui/tokens/spacing.stylex.ts'

const signaturePadRoot = stylex.create({
  base: {
    display: 'flex',
    flexDirection: 'column',
    gap: spacing._1_5,
    width: '100%',
  },
})

const signaturePadLabel = stylex.create({
  base: {
    fontWeight: fontWeights.medium,
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
    color: semanticColors.fg,
    opacity: {
      default: null,
      ':is([data-disabled])': 0.5,
    },
  },
})

// The drawing surface. Strokes are filled with `currentColor`, so the
// semantic fg color keeps the ink legible in light and dark mode.
const signaturePadControl = stylex.create({
  base: {
    position: 'relative',
    width: '100%',
    touchAction: 'none',
    userSelect: 'none',
    color: semanticColors.fg,
    borderRadius: semanticRadii.panel,
    borderWidth: '1px',
    cursor: {
      default: 'crosshair',
      ':is([data-disabled])': 'not-allowed',
    },
    opacity: {
      default: null,
      ':is([data-disabled])': 0.5,
    },
    outlineWidth: {
      default: null,
      ':focus-visible': 'var(--focus-ring-width, 0)',
    },
    outlineOffset: {
      default: null,
      ':focus-visible': '0px',
    },
    outlineStyle: {
      default: null,
      ':focus-visible': 'solid',
    },
    outlineColor: {
      default: null,
      ':focus-visible': colorPalette.focusRing,
    },
  },
})

const signaturePadControlSizes = stylex.create({
  sm: {
    height: sizes._32,
  },
  md: {
    height: sizes._40,
  },
  lg: {
    height: sizes._48,
  },
})

// `outline` matches the file-upload dropzone (dashed border on the page
// background); `subtle` matches the subtle input (muted fill, no border).
const signaturePadControlVariants = stylex.create({
  outline: {
    backgroundColor: semanticColors.bg,
    borderStyle: 'dashed',
    borderColor: {
      default: semanticColors.border,
      ':hover': semanticColors.borderEmphasized,
      ':is([data-disabled])': semanticColors.border,
      ':focus-visible': colorPalette.focusRing,
    },
  },
  subtle: {
    backgroundColor: semanticColors.bgMuted,
    borderStyle: 'solid',
    borderColor: {
      default: 'transparent',
      ':focus-visible': colorPalette.focusRing,
    },
  },
})

const signaturePadSegment = stylex.create({
  base: {
    position: 'absolute',
    inset: 0,
    width: '100%',
    height: '100%',
    overflow: 'visible',
    pointerEvents: 'none',
    fill: 'currentColor',
  },
})

// The baseline to sign on.
const signaturePadGuide = stylex.create({
  base: {
    position: 'absolute',
    insetInline: spacing._4,
    bottom: '28%',
    borderBottomWidth: '1px',
    borderBottomStyle: 'dashed',
    borderBottomColor: semanticColors.borderEmphasized,
    pointerEvents: 'none',
  },
})

const signaturePadClearTrigger = stylex.create({
  base: {
    position: 'absolute',
    top: spacing._2,
    insetInlineEnd: spacing._2,
    zIndex: 1,
    display: {
      default: 'inline-flex',
      ':is([hidden])': 'none',
    },
    alignItems: 'center',
    justifyContent: 'center',
    width: sizes.controlXs,
    height: sizes.controlXs,
    borderRadius: semanticRadii.control,
    color: {
      default: semanticColors.fgMuted,
      ':hover': semanticColors.fg,
    },
    backgroundColor: {
      default: 'transparent',
      ':hover': semanticColors.bgSubtle,
    },
    cursor: {
      default: 'pointer',
      ':disabled': 'not-allowed',
    },
    outlineWidth: {
      default: null,
      ':focus-visible': '2px',
    },
    outlineOffset: {
      default: null,
      ':focus-visible': '0px',
    },
    outlineStyle: {
      default: null,
      ':focus-visible': 'solid',
    },
    outlineColor: {
      default: null,
      ':focus-visible': colorPalette.focusRing,
    },
  },
})

export type SignaturePadVariant = keyof typeof signaturePadControlVariants

export type SignaturePadSize = keyof typeof signaturePadControlSizes

const signaturePadRecipe = defineSlotRecipe({
  slots: {
    root: { styles: signaturePadRoot },
    label: { styles: signaturePadLabel },
    control: {
      styles: signaturePadControl,
      sizes: signaturePadControlSizes,
      variants: signaturePadControlVariants,
    },
    segment: { styles: signaturePadSegment },
    guide: { styles: signaturePadGuide },
    clearTrigger: { styles: signaturePadClearTrigger },
  },
  defaultVariants: { variant: "outline", size: "md" },
});

const chrome = stylex.create({
  btnReset: {
    appearance: "none",
    borderWidth: 0,
    borderStyle: "none",
    padding: 0,
    margin: 0,
    fontFamily: "inherit",
    fontSize: "inherit",
  },
});

function ClearIcon(props: React.ComponentProps<"svg">) {
  return (
    <svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true" {...props}>
      <path
        d="M2.5 8a5.5 5.5 0 1 0 1.6-3.9M2.5 2.5v2.6h2.6"
        stroke="currentColor"
        strokeWidth="1.5"
        strokeLinecap="round"
        strokeLinejoin="round"
      />
    </svg>
  );
}

const { withProvider, withContext } = createSlotRecipeContext(signaturePadRecipe);

const StyledRoot = withProvider(ArkSignaturePad.Root, "root", "SignaturePadRoot");

/**
 * Root — Ark's signature-pad machine. Strokes are filled with
 * `currentColor` (the control's semantic fg) unless `drawing.fill` is set,
 * so ink follows light/dark mode.
 */
function Root(props: React.ComponentProps<typeof StyledRoot>) {
  const { drawing, ...rest } = props;
  return <StyledRoot drawing={{ size: 3, simulatePressure: true, ...drawing }} {...rest} />;
}
Root.displayName = "SignaturePadRoot";

const StyledClearTrigger = withContext(
  ArkSignaturePad.ClearTrigger,
  (v) => [chrome.btnReset, ...resolveSlotStyles(signaturePadRecipe.slots.clearTrigger, v)],
  "SignaturePadClearTrigger",
);

/** Clears the pad; hidden while empty. Ships a default reset icon. */
function ClearTrigger(props: React.ComponentProps<typeof StyledClearTrigger>) {
  const { children, ...rest } = props;
  return (
    <StyledClearTrigger aria-label="Clear signature" {...rest}>
      {children ?? <ClearIcon />}
    </StyledClearTrigger>
  );
}
ClearTrigger.displayName = "SignaturePadClearTrigger";

/**
 * HiddenInput — carries the signature into form submissions. Without a
 * `value` it fills in an SVG data URL of the current strokes (empty when
 * the pad is blank).
 */
function HiddenInput(
  props: Omit<React.ComponentProps<typeof ArkSignaturePad.HiddenInput>, "value"> & {
    value?: string;
  },
) {
  const { value, ...rest } = props;
  const api = useSignaturePadContext();
  const [dataUrl, setDataUrl] = useState("");
  const pathsKey = api.paths.join("\n");
  useEffect(() => {
    if (value !== undefined) return;
    if (!pathsKey) {
      setDataUrl("");
      return;
    }
    let live = true;
    api.getDataUrl("image/svg+xml").then((url) => {
      if (live) setDataUrl(url);
    });
    return () => {
      live = false;
    };
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [pathsKey, value]);
  return <ArkSignaturePad.HiddenInput value={value ?? dataUrl} {...rest} />;
}
HiddenInput.displayName = "SignaturePadHiddenInput";

/**
 * SignaturePad — Ark UI's signature-pad machine with the StyleX slot
 * recipe: a drawing surface in the file-upload dropzone look (`outline`) or
 * a muted fill (`subtle`), sized `sm`/`md`/`lg`, with a dashed guide line
 * and a clear button. Draw with mouse, pen or touch.
 */
export const SignaturePad = {
  Root,
  Label: withContext(ArkSignaturePad.Label, "label", "SignaturePadLabel"),
  Control: withContext(ArkSignaturePad.Control, "control", "SignaturePadControl"),
  Segment: withContext(ArkSignaturePad.Segment, "segment", "SignaturePadSegment"),
  Guide: withContext(ArkSignaturePad.Guide, "guide", "SignaturePadGuide"),
  ClearTrigger,
  HiddenInput,
  Context: ArkSignaturePad.Context,
};

export type SignaturePadRootProps = React.ComponentProps<typeof SignaturePad.Root>;
export type {
  SignaturePadDrawDetails,
  SignaturePadDrawEndDetails,
} from "@ark-ui/react/signature-pad";
```
