GooseUI

Components

OTP Input

New

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

: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

npx shadcn@latest add @gooseui/otp-input
pnpm dlx shadcn@latest add @gooseui/otp-input
yarn dlx shadcn@latest add @gooseui/otp-input
bunx --bun shadcn@latest add @gooseui/otp-input

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

PropTypeDefaultDescription
InputOTP: maxLengthnumber—Number of characters.
InputOTP: value / onChangestring / (value: string) => void—Controlled code and change handler.
InputOTP: onComplete(value: string) => void—Called when all slots are filled.
InputOTP: patternstring—Regular expression used to filter input.
InputOTP: autoCompletestring"one-time-code"Enables SMS code suggestions.
InputOTP: disabledbooleanfalseDisables input.
InputOTP: status"idle" | "pending" | "success" | "error""idle"Check state: pending locks input, success confirms, error shakes the group.
aria-invalidboolean—Marks the input or slot as invalid.
InputOTPSlot: indexnumber—Index of a slot, starting at zero.
className / containerClassNamestring—Additional CSS classes.