Skip to content
Vertical Jump Designs-uiFront-End Studio
Get Pro

v3.9 is out.

Forms

PinInput

Free2.9 KB gzipped

A one-time-code or PIN entry shown as a row of cells.

Accessibility: WCAG 2.2 AA · No A or AA violations in light or dark mode · Keys: Backspace, Arrow Left, Arrow Right and 4 more · Full report

Import

tsx
import { PinInput } from "@vjdesigns/vjdesigns-ui";

Importing only PinInput adds about 2.9 KB of minified, gzipped JavaScript to your app (React not included). The stylesheet is shared by every component and loaded once: 75.1 KB gzipped.

Examples

Verification code

Typing moves to the next box, Backspace moves back, and pasting a full code fills every box.

Enter the 6-digit code we sent you.

tsx
import { useState } from "react";
import { Field, PinInput, Stack, Text } from "@vjdesigns/vjdesigns-ui";

export function VerificationCode() {
  const [status, setStatus] = useState("Enter the 6-digit code we sent you.");
  return (
    <Stack gap={3} align="center">
      <Field label="Verification code">
        <PinInput separator={3} onComplete={(code) => setStatus(`Checking ${code}…`)} autoComplete="one-time-code" />
      </Field>
      <Text size="sm" tone="muted" role="status">
        {status}
      </Text>
    </Stack>
  );
}

Masked

mask hides the characters, as for a PIN.

tsx
import { Field, PinInput } from "@vjdesigns/vjdesigns-ui";

export function Masked() {
  return (
    <Field label="PIN">
      <PinInput length={4} mask />
    </Field>
  );
}

Accessibility

Give the code one visible label with Field. mask shows dots and makes the cells type="password", so screen readers don't speak a PIN aloud, and onComplete fires once the last cell is filled.

4 digits

tsx
import { useState } from "react";
import { Field, PinInput, Stack, Text } from "@vjdesigns/vjdesigns-ui";

export function Accessibility() {
  const [status, setStatus] = useState("");
  return (
    <Stack gap={3}>
      <Field label="Card PIN" hint="4 digits">
        <PinInput length={4} mask onComplete={() => setStatus("PIN entered.")} />
      </Field>
      <Text size="sm" tone="muted" role="status">
        {status}
      </Text>
    </Stack>
  );
}

Translated

The cells hold digits, which read the same in every language; the label and hint are your own text. LocaleProvider sets lang, so screen readers use Japanese for them.

メールに届いた 6 桁のコード

tsx
import { Field, PinInput, LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import ja from "@vjdesigns/vjdesigns-ui/locales/ja";

export function Translated() {
  return (
    <LocaleProvider locale="ja" messages={ja}>
      <Field label="確認コード" hint="メールに届いた 6 桁のコード">
        <PinInput length={6} />
      </Field>
    </LocaleProvider>
  );
}

Right to left

The first example again, inside a right-to-left LocaleProvider (Arabic). Layout, spacing and arrow icons mirror, and the components' built-in text is translated. The example's own text stays in English.

Verification code

Enter the 6-digit code we sent you.

tsx
import { LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import ar from "@vjdesigns/vjdesigns-ui/locales/ar";

// VerificationCode is the "Verification code" example above.
<LocaleProvider locale="ar" messages={ar}>
  <VerificationCode />
</LocaleProvider>

Usage notes

Built on one real `<input>`. The whole code lives in a single native input that spans the cells with transparent text; the cells only mirror its value and caret. That keeps everything the platform does for code fields: native paste, autoComplete="one-time-code" SMS and email suggestions on iOS and Android, password managers, form submission with name, and one control with one accessible name for assistive technology (instead of six "Digit N of 6" fields). The cells are aria-hidden.

Typing fills the active cell and moves on; Backspace deletes; Arrow Left/Right, Home, and End move between cells; clicking a cell selects it so the next key replaces it. Pasting or autofilling a full code fills every cell (spaces and dashes are stripped). Paste and autofill are never blocked (SC 3.3.8), and there is no timeout (SC 2.2.1).

Give it an accessible name: wrap it in a Field (recommended, which also wires hint, error, invalid, disabled, and read-only), or pass aria-label / aria-labelledby.

tsx
<Field label="Verification code" hint="We sent a 6-digit code to your email.">
  <PinInput onComplete={verify} />
</Field>

API reference

PinInput

PinInput props
PropTypeDefault
length

Number of cells (characters in the code).

number6
value

Controlled value (the whole code as one string).

string—
defaultValue

Initial value when uncontrolled.

string""
onValueChange

Called with the new code on every change (typing, deleting, pasting, autofill).

(value: string) => void—
onComplete

Called with the code when the user fills the last empty cell. Use it to verify or auto-submit. Not called for programmatic value changes.

(value: string) => void—
type

Accepted characters. numeric sets inputMode="numeric" and pattern="[0-9]*" (numeric keypad on phones); alphanumeric accepts A-Z, a-z, and 0-9. Other characters (spaces, dashes, ...) are stripped.

"numeric""alphanumeric""numeric"
mask

Shows a dot in filled cells instead of the character, for PINs. The input becomes type="password" so screen readers don't speak the digits.

booleanfalse
placeholder

Character shown in empty cells, such as "○" or "·". Decorative.

string—
size

Cell size and digit size. Inherits from a surrounding Field.

"sm""md""lg""md"
variant

Visual style, matching Input.

"outline""filled""outline"
radius

Cell corner rounding. When omitted, uses --field-radius.

"none""xs""sm""md""lg""xl""2xl""pill"—
invalid

Marks the code as invalid: sets aria-invalid and a danger border on every cell. Pair it with a visible error message (a Field does this). Inherits from a surrounding Field.

booleanfalse
separator

Draws a separator between groups of cells. A number splits into groups of that size (3 on a 6-cell code gives 3-3); an array lists the cell counts after which a separator appears ([2, 4] gives 2-2-2).

number | number[]—
separatorContent

Content of each separator. Decorative (hidden from assistive technology).

ReactNode"–"
inputClassName

Class name for the hidden <input> element. className goes to the wrapper.

string—
ref

Ref to the <input> element that holds the code.

Ref<HTMLInputElement>—

Also accepts native <input> attributes, plus className, style and ref.

See what changed in each version in the Changelog.

Accessibility report

PinInput targets WCAG 2.2 AA. Below: a live axe-core audit of this page's examples, Lighthouse scores for the page in both modes, the accessibility behavior built into the component, and the checks only a person can do.

axe-core audit (live)

Running accessibility audit

Checking the examples above…

Lighthouse audit

Light mode

Score 100

37 passed · 0 failed · 28 not applicable · 10 to check by hand

Dark mode

Score 100

37 passed · 0 failed · 28 not applicable · 10 to check by hand

Lighthouse 13.5.0 audits the whole docs page (header and sidebar included), not just the examples, in English. Last run 11/27/2026. Some failed audits carry no weight in the score, so a page can score 100 and still list one.

Built-in behavior

Keyboard

Keyboard
KeyAction
TypingFills the next cell; pasting fills them all.
BackspaceClears the previous cell.
Arrow LeftArrow RightMoves between cells.
HomeArrow UpFirst cell.
EndArrow DownAfter the last filled cell.

One native input holds the whole code, so it's one tab stop and one field for screen readers.

Roles and states

Roles and states
ElementRoleStates and properties
<input>textboxaria-label or label, aria-describedby, aria-invalid, autocomplete="one-time-code"
Cellsnonearia-hidden="true": they mirror the input

Manual checks

Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.

Manual accessibility checks
CheckWhat to testWCAG 2.2
KeyboardEvery action works with Tab, Shift+Tab, Enter, Space and the arrow keys, and focus never gets stuck.2.1.1 (A), 2.1.2 (A)
FocusFocus moves in a logical order, is always visible, and isn't hidden behind sticky headers.2.4.3 (A), 2.4.7 (AA), 2.4.11 (AA), 2.4.13 (AAA)
Screen readersNames, roles and states are announced correctly, and status changes are announced without moving focus.1.3.1 (A), 4.1.2 (A), 4.1.3 (AA)
ColorMeaning never depends on color alone; your own colors meet contrast in both modes.1.4.1 (A), 1.4.3 (AA), 1.4.11 (AA), 1.4.6 (AAA)
Zoom and reflowAt 200% text size and at 320px wide (400% zoom), nothing is cut off and no sideways scrolling is needed.1.4.4 (AA), 1.4.10 (AA), 1.4.12 (AA)
Pointer targetsClick and tap targets are at least 24×24px (44×44px for AAA), or spaced so they don't overlap.2.5.8 (AA), 2.5.5 (AAA)
MotionAnimations respect the reduced-motion setting.2.3.3 (AAA)