Input OTP
OTP input backed by Base UI OTPFieldPreview with grouped slots, separator, and numeric/alphanumeric validation modes.
Basic
6 slots — default numeric OTP
Value: —
4 slots — PIN
separator — 3+3 split
separator={4} — 4+4 split on 8 slots
Variants
mask — password mode
validationType: alphanumeric
State
Disabled
OTPWrapper (field-wrapper)
With label
Error state
Invalid code. Please try again.
Installation
npx shadcn@latest add @glrk-ui/input-otpIf you haven't set up the prerequisites yet, check out registry setup.
Usage
Standalone (InputOTPWrapper)
import { InputOTPWrapper } from "@/components/ui/input-otp"
const [value, setValue] = useState('')
<InputOTPWrapper
length={6}
value={value}
onValueChange={(v) => setValue(v)}
/>With separator
// Split in half automatically (3+3 for length=6)
<InputOTPWrapper length={6} separator />
// Split after specific slot (4+4)
<InputOTPWrapper length={8} separator={4} />Mask (password mode)
<InputOTPWrapper length={6} mask />Alphanumeric validation
<InputOTPWrapper length={6} validationType="alphanumeric" />With field label and error (OTPWrapper)
OTPWrapper wraps InputOTPWrapper inside a Field with label and error display. Import from field-wrapper:
import { OTPWrapper } from "@/components/ui/field-wrapper"
<OTPWrapper
name="otp"
label="Verification code"
length={6}
separator
value={value}
onValueChange={(v) => setValue(v)}
/>With validation error
<OTPWrapper
name="otp"
label="Verification code"
length={6}
invalid
error={{ message: "Invalid code. Please try again." }}
/>React Hook Form
import { OTPWrapper } from "@/components/ui/field-wrapper-rhf"
<OTPWrapper name="otp" label="Verification code" control={form.control} length={6} />TanStack Form
<form.AppField
name="otp"
validators={{
onChange: ({ value }) =>
value.length < 6 ? "Enter all 6 digits" : undefined,
}}
>
{field => <field.OTPField label="Verification code" length={6} separator />}
</form.AppField>Reference
InputOTPWrapper
Prop
Type