Input OTP

uistable

Input OTP — from shadcn/ui (radix-nova style).

npx shadcn add @krawma/input-otp

npm: input-otp@^1.4.2, lucide-react@^1.22.0 · registry: @krawma/utils

Preview

States
focus-visibledisabledcomplete
Keyboard
BackspaceArrowLeftArrowRightDelete
Depends on
utils

Purpose

A segmented one-time-code / PIN input (built on input-otp) — one visible slot per character, for verification codes and short numeric secrets.

Anatomy

InputOTP (owns the value + maxLength) › InputOTPGroupInputOTPSlot (one per digit), with InputOTPSeparator between groups.

Style

No variants — token-backed slots; the active slot shows a caret, filled slots the entered character.

Behavior & functionality

  • Controlled (value + onChange) with a fixed maxLength; typing advances, Backspace moves back, paste distributes across slots.
  • Fire onComplete when all slots are filled.

Accessibility

  • Renders a single logical input under the hood — screen readers treat it as one field; label it (aria-label) and set inputMode/autoComplete="one-time-code".
  • Arrows / Backspace move between slots; the focused slot is indicated.

Do / Don't

  • ✅ Set autoComplete="one-time-code" and act on onComplete.
  • ❌ Don't use for general numeric entry — use number-input.