Input OTP
One-time code input with per-digit slots, paste-to-fill, patterns, separators, completion callback, and RTL.
Installation#
pnpm dlx shadcn@latest add @davinciui/input-otpUsage#
About
InputOTP renders one input per digit with auto-advance, smart backspace, paste-to-fill, and direction-aware arrow keys. A regex pattern decides which characters stick — everything else is rejected without moving focus.
Composition
Length, pattern, separators, and completion are props on one control — no compound imports. Wire it controlled for forms, or drop it in uncontrolled for the common verify-code flow.
API Reference#
| Prop | Type | Default |
|---|---|---|
lengthNumber of slots. | number | 6 |
valueControlled joined value. | string | — |
defaultValueUncontrolled initial value. | string | "" |
onValueChangeFires on every change. | (value: string) => void | — |
onCompleteFires once when every slot is filled. | (value: string) => void | — |
patternAllowed characters as a regex source. | string | "[0-9]" |
uppercaseUppercase alphabetical input. | boolean | false |
separatorAfterSlot indexes after which a separator renders. | number[] | — |
disabledDisable all slots. | boolean | false |
invalidError state with aria-invalid. | boolean | false |
autoFocusFocus the first slot on mount. | boolean | false |
inputModeMobile keyboard hint. | "text" | "numeric" | "text" |
dirText direction with mirrored arrows. | "ltr" | "rtl" | "ltr" |
classNameExtra classes for the root. | string | — |
slotClassNameExtra classes for each slot. | string | — |
Accessibility#
A role group labelled 'One-time code' contains per-slot inputs labelled 'Digit n of N'. Arrow keys, Home, End, Backspace, Delete, and paste are handled, focus auto-advances, and disabled or aria-invalid states follow the props.
Motion#
This is a static input group; only a CSS color transition on each slot changes state. There is no animation loop or transform motion, so prefers-reduced-motion needs no special handling.
View source
Keep in mind
Need a custom component?
I build bespoke UI components & websites tailored to your brand.

