A one-time password input with individual character slots, built on input-otp.
A composable OTP (one-time password) input built on the input-otp library. It renders individual character slots grouped together, with optional separators between groups. Supports focus management, fake caret animation, and validation states.
import {
InputOTP,
InputOTPGroup,
InputOTPSlot,
InputOTPSeparator,
} from "@/components/ui/input-otp"
export default function InputOtpDemo() {
return (
<InputOTP maxLength={6}>
<InputOTPGroup>
<InputOTPSlot index={0} />
<InputOTPSlot index={1} />
<InputOTPSlot index={2} />
</InputOTPGroup>
<InputOTPSeparator />
<InputOTPGroup>
<InputOTPSlot index={3} />
<InputOTPSlot index={4} />
<InputOTPSlot index={5} />
</InputOTPGroup>
</InputOTP>
)
}
import {
InputOTP,
InputOTPGroup,
InputOTPSlot,
InputOTPSeparator,
} from "@/components/ui/input-otp"<InputOTP maxLength={6}>
<InputOTPGroup>
<InputOTPSlot index={0} />
<InputOTPSlot index={1} />
<InputOTPSlot index={2} />
</InputOTPGroup>
<InputOTPSeparator />
<InputOTPGroup>
<InputOTPSlot index={3} />
<InputOTPSlot index={4} />
<InputOTPSlot index={5} />
</InputOTPGroup>
</InputOTP><InputOTP maxLength={6}>
<InputOTPGroup>
<InputOTPSlot index={0} />
<InputOTPSlot index={1} />
<InputOTPSlot index={2} />
<InputOTPSlot index={3} />
<InputOTPSlot index={4} />
<InputOTPSlot index={5} />
</InputOTPGroup>
</InputOTP>Use InputOTPSeparator to visually divide slot groups, such as a 3-3 pattern.
<InputOTP maxLength={6}>
<InputOTPGroup>
<InputOTPSlot index={0} />
<InputOTPSlot index={1} />
<InputOTPSlot index={2} />
</InputOTPGroup>
<InputOTPSeparator />
<InputOTPGroup>
<InputOTPSlot index={3} />
<InputOTPSlot index={4} />
<InputOTPSlot index={5} />
</InputOTPGroup>
</InputOTP><InputOTP maxLength={4}>
<InputOTPGroup>
<InputOTPSlot index={0} />
<InputOTPSlot index={1} />
<InputOTPSlot index={2} />
<InputOTPSlot index={3} />
</InputOTPGroup>
</InputOTP>The root input component. Wraps OTPInput from input-otp.
| Prop | Type | Default | Description |
|---|---|---|---|
maxLength | number | — | The total number of OTP characters. |
value | string | — | Controlled value. |
onChange | (value: string) => void | — | Callback when the value changes. |
containerClassName | string | — | Class name applied to the outer container <div>. |
className | string | — | Class name applied to the hidden <input> element. |
A <div> that groups consecutive InputOTPSlot components with connected borders.
| Prop | Type | Default |
|---|---|---|
className | string | — |
children | ReactNode | — |
A single character slot. Reads its state (character, active, caret) from OTPInputContext using the provided index.
| Prop | Type | Default | Description |
|---|---|---|---|
index | number | — | The zero-based index of this slot within the OTP input. |
className | string | — |
A visual separator between slot groups. Renders a dash icon by default.
| Prop | Type | Default |
|---|---|---|
className | string | — |
children | ReactNode | — |