Skip to Content
zjkm-ui
Components

OTP Input

One box per digit for one-time codes.

Props
6
<OtpInput />

Installation

npx shadcn@latest add https://ui.zjkm.tech/r/otp-input.json
import { OtpInput } from "@/components/otp-input"

Using JavaScript? Set tsx: false in components.json and the CLI converts it.

New to shadcn? Run npx shadcn@latest init first. The CLI needs components.json and the @/ import alias.

Usage

One box per digit. Typing moves to the next box, Backspace moves back, and pasting a code fills every box. The first box asks the browser to autofill codes from SMS, and the group has a name for screen readers.

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

export function Verify({ verify }: { verify: (code: string) => void }) {
  return <OtpInput length={6} onComplete={verify} />;
}

Props

PropTypeDefaultDescription
lengthnumber6Number of digits.
labelstring"One-time code"Accessible name of the group.
onComplete(code: string) => voidCalled when every box is filled.
classNamestringClasses for the group.

It has no animation, so reduced motion changes nothing.

On this page