Skip to content
Logic2BUI

Search docs

Search components and documentation

New
Menu

Input OTP

An accessible one-time-password input with individual character slots.

Installation

npx logic2b@next add input-otp

Usage

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

<InputOTP aria-label="One-time code" 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>

Built on input-otp.

Examples

Digits Only

Pass a pattern to restrict input — REGEXP_ONLY_DIGITS is re-exported by input-otp.

Controlled

Enter your PIN

Accessibility

  • Renders a single real <input> behind the slots, so browser and password manager autofill of one-time codes (autocomplete="one-time-code") works and the field is announced normally by screen readers.
  • Fully keyboard operable: typing advances through slots, Backspace moves back, and arrow keys plus paste are handled by the underlying input-otp primitive.
  • Invalid state is driven by aria-invalid, which styles the active slot with the destructive ring.
  • Give the underlying field an accessible name with a visible <label>, aria-label or aria-labelledby; every bundled example does so explicitly.

Live playground

Edit the component props and inspect the exact JSX before copying it. The preview loads only when this section enters the viewport.

Generated JSX
<InputOTP
  maxLength={6}
  defaultValue="248135"
  aria-label="Verification code"
>
  <InputOTPGroup>
    <InputOTPSlot
      index={0}
     />
    <InputOTPSlot
      index={1}
     />
    <InputOTPSlot
      index={2}
     />
  </InputOTPGroup>
  <InputOTPSeparator />
  <InputOTPGroup>
    <InputOTPSlot
      index={3}
     />
    <InputOTPSlot
      index={4}
     />
    <InputOTPSlot
      index={5}
     />
  </InputOTPGroup>
</InputOTP>

API reference

Generated from the public TypeScript exports in src/ui/input-otp.tsx.

View JSON

InputOTP

Component
Props: React.ComponentProps<typeof OTPInput>

InputOTPGroup

Component
Props: React.ComponentProps<"div">

InputOTPSlot

Component
Props: React.ComponentProps<"div"> & { index: number }
PropTypeRequiredDefaultDescription
indexnumberYes——

InputOTPSeparator

Component
Props: React.ComponentProps<"div">

Accessibility contract

Machine-readable behavior and consumer responsibilities for input-otp.

View JSON
Support
Primitive-managed
Pattern
one-time-code textbox
input-otp
Keyboard interactions for input-otp
KeysBehavior
BackspaceClear the current slot and move backward.
ArrowLeft ArrowRightMove between code positions where supported.

Built-in semantics

  • A single input owns the value while visual slots mirror caret/invalid state.

Consumer responsibilities

  • Provide a label, autocomplete=one-time-code where appropriate and never rely only on SMS access.