Xzero UI
Pro library

OTP input

A six digit verification flow with paste support and keyboard navigation.

$ pnpm dlx shadcn@4.23.0 add @xzero-ui/otp-input
Live · keyboard ready

Use it as part of verification after you have sent a code. Validate the code on your server.

When to use

When not to use

Installation

Register both Xzero UI namespaces in your project's components.json:

{
  "registries": {
    "@xzero-ui": "https://mcp.xzero.co.uk/r/{name}.json",
    "@xzero-ui-pro": "https://mcp.xzero.co.uk/r/pro/{name}.json"
  }
}
npx shadcn@4.23.0 add @xzero-ui/otp-input

Install xzero-foundation once, and import @/components/xzero/foundation.css in your app root. No Xzero token is used by this snapshot. For sample portraits, photos, fonts, or logos, download https://mcp.xzero.co.uk/install-assets.mjs and run node xzero-install-assets.mjs <receiving-project>.

Usage

import { useState } from "react";
import { OtpInput } from "@/components/xzero/otp-input/otp-input";

export function VerifyCode() {
  const [code, setCode] = useState("");
  return (
    <OtpInput
      label="Verification code"
      description="We sent a 6-digit code to your email."
      value={code}
      onChange={next => { setCode(next); if (next.length === 6) verify(next); }}
      autoFocus
    />
  );
}

API reference

OtpInput

A row of single-character inputs for one-time codes, with paste fill, a gliding focus ring, and animated helper and error copy.

PropTypeDefaultDescription
label (required)string–Visible label and group name; each slot is labelled with it plus its position.
lengthnumber6Number of slots.
valuestring""Current code. Controlled: update it from onChange.
onChange(value: string) => void–Called with the full code after every edit or paste.
descriptionstring–Helper text below the slots.
errorstring–Error text. Sets aria-invalid and shakes the row once when it changes.
inputMode"numeric" | "text""numeric"numeric strips non-digits.
autoFocusbooleanfalseFocuses the first slot on mount.
disabledbooleanfalseDisables every slot.
classNamestring–Merged onto the field wrapper.

Keyboard interactions

KeysAction
0-9 / charactersFills the slot and moves to the next one.
ArrowLeft / ArrowRightMoves between slots.
BackspaceOn an empty slot, clears the previous one and moves back.
DeleteClears the current slot.
Cmd/Ctrl + VPastes a code across the slots from the focused one.

Accessibility

Motion

Responsive behavior

Performance

Notes for AI

Guidance for AI tools

Blocks are complete, self-contained screens with sample data. Replace the sample data and connect the callbacks described above. Follow the declared prop types and do not invent props. Keep keyboard access, reduced motion support, and both light and dark themes intact when adapting it.

Full library index: https://ui.xzero.co.uk/llms.txt

Browse all components