Skip to content

shadcn.io is not affiliated with official shadcn/ui

Shadcn Input OTP for React

Accessible one-time password input.

1
2
3
4
5
6

Installation

bunx --bun shadcn@latest add https://kit.dev/r/radix/input-otp.json

Anatomy

InputOTP
├── InputOTPGroup
│   ├── InputOTPSlot
│   └── InputOTPSlot
├── InputOTPSeparator
└── InputOTPGroup
    ├── InputOTPSlot
    └── InputOTPSlot

Usage

import {
  InputOTP,
  InputOTPGroup,
  InputOTPSlot,
} from "@/components/ui/input-otp";
<InputOTP defaultValue={["1", "2", "3", "4", "5", "6"]}>
  <InputOTPGroup>
    <InputOTPSlot index={0} />
    <InputOTPSlot index={1} />
    <InputOTPSlot index={2} />
    <InputOTPSlot index={3} />
    <InputOTPSlot index={4} />
    <InputOTPSlot index={5} />
  </InputOTPGroup>
</InputOTP>

Accessibility

KeyDescription
Backspace
Delete backward.
Delete
Delete.
ArrowLeft
Move left.
ArrowRight
Move right.
Enter
Activate the focused item.
Home
Go to the start.
End
Go to the end.

Demos

Pattern

Digits-only OTP via type="numeric".

Separator

Separators between OTP slot groups.

Disabled

Disabled OTP with a prefilled value.

Controlled

Controlled OTP value with live feedback.

Invalid

Invalid OTP slots via aria-invalid.

Four Digits

Four-digit PIN with numeric input.

Alphanumeric

Alphanumeric OTP with a separator.

Form

Verification card with Field-wrapped OTP.

Rtl

Right-to-left field. The code stays left-to-right; the label follows the field direction.

API Reference

InputOTP

PropType
AttributeType

InputOTPGroup

PropType
AttributeType

InputOTPSlot

PropType
AttributeType

InputOTPSeparator

PropType
className?string
AttributeType