Forms
PinInput
Free2.9 KB gzippedA 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
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.
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.
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
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 桁のコード
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.
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.
<Field label="Verification code" hint="We sent a 6-digit code to your email.">
<PinInput onComplete={verify} />
</Field>
API reference
PinInput
| Prop | Type | Default |
|---|---|---|
lengthNumber of cells (characters in the code). | number | 6 |
valueControlled value (the whole code as one string). | string | — |
defaultValueInitial value when uncontrolled. | string | "" |
onValueChangeCalled with the new code on every change (typing, deleting, pasting, autofill). | (value: string) => void | — |
onCompleteCalled with the code when the user fills the last empty cell. Use it to verify or auto-submit. Not called for programmatic | (value: string) => void | — |
typeAccepted characters. | "numeric""alphanumeric" | "numeric" |
maskShows a dot in filled cells instead of the character, for PINs. The input becomes | boolean | false |
placeholderCharacter shown in empty cells, such as | string | — |
sizeCell size and digit size. Inherits from a surrounding | "sm""md""lg" | "md" |
variantVisual style, matching | "outline""filled" | "outline" |
radiusCell corner rounding. When omitted, uses | "none""xs""sm""md""lg""xl""2xl""pill" | — |
invalidMarks the code as invalid: sets | boolean | false |
separatorDraws a separator between groups of cells. A number splits into groups of that size ( | number | number[] | — |
separatorContentContent of each separator. Decorative (hidden from assistive technology). | ReactNode | "–" |
inputClassNameClass name for the hidden | string | — |
refRef to the | 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)
Checking the examples above…
Lighthouse audit
Light mode
Score 10037 passed · 0 failed · 28 not applicable · 10 to check by hand
Dark mode
Score 10037 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
| Key | Action |
|---|---|
| Typing | Fills the next cell; pasting fills them all. |
| Backspace | Clears the previous cell. |
| Arrow LeftArrow Right | Moves between cells. |
| HomeArrow Up | First cell. |
| EndArrow Down | After 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
| Element | Role | States and properties |
|---|---|---|
<input> | textbox | aria-label or label, aria-describedby, aria-invalid, autocomplete="one-time-code" |
| Cells | none | aria-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.
| Check | What to test | WCAG 2.2 |
|---|---|---|
| Keyboard | Every 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) |
| Focus | Focus 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 readers | Names, 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) |
| Color | Meaning 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 reflow | At 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 targets | Click 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) |
| Motion | Animations respect the reduced-motion setting. | 2.3.3 (AAA) |