An accessible one-time code input uses a single visually hidden field to power its visible slots. Users can type or paste the entire code, and autocomplete="one-time-code" enables SMS code suggestions on supported devices. Compose slots into groups and add a separator wherever needed.
Browser Support
Feature
Baseline
Your browser
:has()
Styles the group and input container based on their contents.
Your browser:
Preview
Enter 123456 to see success or any other code to see the error state.
Enter verification code
Enter the code sent to your phone.
Code valid for 5:00
Hint: 1234
Installation
Usage
import { InputOTP, InputOTPGroup, InputOTPSlot, InputOTPSeparator } from "@/components/ui/otp-input"
<InputOTP maxLength={6} aria-label="One-time code">
<InputOTPGroup>
{Array.from({ length: 6 }, (_, i) => <InputOTPSlot key={i} index={i} />)}
</InputOTPGroup>
</InputOTP>Examples
Set status="pending" while the code is checked, then "success" or "error" to confirm (green) or shake (red) the group. Override the green with the --gooseui-otp-success CSS variable.
Six slots
<InputOTP maxLength={6} aria-label="One-time code">
<InputOTPGroup>
{Array.from({ length: 6 }, (_, i) => <InputOTPSlot key={i} index={i} />)}
</InputOTPGroup>
</InputOTP>Groups with separator
<InputOTP maxLength={6} aria-label="One-time code">
<InputOTPGroup>
{[0, 1, 2].map(i => <InputOTPSlot key={i} index={i} />)}
</InputOTPGroup>
<InputOTPSeparator />
<InputOTPGroup>
{[3, 4, 5].map(i => <InputOTPSlot key={i} index={i} />)}
</InputOTPGroup>
</InputOTP>Digits only
<InputOTP maxLength={6} pattern="^[0-9]+$" aria-label="One-time code">
<InputOTPGroup>{/* six slots */}</InputOTPGroup>
</InputOTP>Error
1
2
3
4
5
6
<InputOTP maxLength={6} aria-invalid aria-label="One-time code">
<InputOTPGroup>
{[0, 1, 2, 3, 4, 5].map(i => <InputOTPSlot key={i} index={i} aria-invalid />)}
</InputOTPGroup>
</InputOTP>Disabled
<InputOTP maxLength={6} disabled aria-label="One-time code">
<InputOTPGroup>{/* six slots */}</InputOTPGroup>
</InputOTP>Props
| Prop | Type | Default | Description |
|---|---|---|---|
| InputOTP: maxLength | number | — | Number of characters. |
| InputOTP: value / onChange | string / (value: string) => void | — | Controlled code and change handler. |
| InputOTP: onComplete | (value: string) => void | — | Called when all slots are filled. |
| InputOTP: pattern | string | — | Regular expression used to filter input. |
| InputOTP: autoComplete | string | "one-time-code" | Enables SMS code suggestions. |
| InputOTP: disabled | boolean | false | Disables input. |
| InputOTP: status | "idle" | "pending" | "success" | "error" | "idle" | Check state: pending locks input, success confirms, error shakes the group. |
| aria-invalid | boolean | — | Marks the input or slot as invalid. |
| InputOTPSlot: index | number | — | Index of a slot, starting at zero. |
| className / containerClassName | string | — | Additional CSS classes. |