Skip to content
SevenOne

Search documentation

Search pages and components

Input OTP

A field for one-time codes, with one 44 × 44px slot per digit and 16px text. The active slot shows the focus ring.

Installation

npx shadcn@latest add @sevenone/input-otp

Usage

import {
  InputOTP,
  InputOTPGroup,
  InputOTPSeparator,
  InputOTPSlot,
} from "@/components/ui/input-otp"

Examples

Default

We sent a 6-digit code to your email.

<Label htmlFor="otp">Verification code</Label>
<InputOTP id="otp" maxLength={6} aria-describedby="otp-hint">
  <InputOTPGroup>
    <InputOTPSlot index={0} />
    <InputOTPSlot index={1} />
    <InputOTPSlot index={2} />
  </InputOTPGroup>
  <InputOTPSeparator />
  <InputOTPGroup>
    <InputOTPSlot index={3} />
    <InputOTPSlot index={4} />
    <InputOTPSlot index={5} />
  </InputOTPGroup>
</InputOTP>
<p id="otp-hint">We sent a 6-digit code to your email.</p>

Digits only

pattern accepts only the characters you allow; inputMode opens the number keyboard on phones.

import { REGEXP_ONLY_DIGITS } from "input-otp"

<Label htmlFor="pin">PIN</Label>
<InputOTP id="pin" maxLength={4} pattern={REGEXP_ONLY_DIGITS} inputMode="numeric">
  <InputOTPGroup>
    <InputOTPSlot index={0} />
    <InputOTPSlot index={1} />
    <InputOTPSlot index={2} />
    <InputOTPSlot index={3} />
  </InputOTPGroup>
</InputOTP>

Accessibility

  • It is one real input under the slots, so screen readers read the whole code and paste works.
  • Connect it to a Label with id and htmlFor, and connect hints and errors with aria-describedby.
  • Use autoComplete="one-time-code" (the default) so phones can fill in the code from a text message.
  • The caret stops blinking when people ask for reduced motion.