Otp Input

A React one time code input where one real input powers the slots, so paste, SMS autofill and screen readers work natively. Has groups, error shake and success.

src/registry/ui/otp-input.tsx/r/otp-input.json

Type 424242 to pass, anything else fails

Paste works too, and SMS autofill on phones.

Alphanumeric, large

Letters are uppercased as you type.

Type or paste a code

Installation#

bash
npx shadcn@latest add @minidev/otp-input

MiniDev UI is in the shadcn registry directory, so the short form works with no setup. Older CLI versions can use the full URL: npx shadcn@latest add https://ui.minidev.pro/r/otp-input.json

Usage#

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

export function Example() {
  return (
    <OtpInput />
  )
}

API reference#

OtpInput props
PropTypeDefault
lengthnumber6
valuestring-
defaultValuestring""
onChange(value: string) => void-
onComplete(value: string) => void-
groupsnumber[]-
pattern"numeric" | "alphanumeric""numeric"
statusStatus"idle"
disabledboolean-
autoFocusboolean-
namestring-
size"default" | "lg""default"
classNamestring-
aria-labelstring-

Examples#

All login and signup components

Learn more