Skip to content
VenusUI
Get started

OTP Input

One-time code entry in separate boxes with paste, autofill and keyboard navigation.

Preview

Installation

npx shadcn@latest add @venusui/otp-input

Run this in a project set up with shadcn. If you haven’t set it up yet, run npx shadcn@latest init first.

Files added to your project

Paths use the default shadcn aliases. The CLI follows the aliases in your components.json.

  • @/components/ui/otp-input.tsx

Usage

The code behind the preview above.

otp-input-demo.tsx

"use client"

import * as React from "react"

import { OtpInput } from "@/components/ui/otp-input"

export default function OtpInputDemo() {
  const [code, setCode] = React.useState("")
  return (
    <div className="flex flex-col items-center gap-3">
      <OtpInput value={code} onValueChange={setCode} />
      <p className="text-sm text-muted-foreground" aria-live="polite">
        {code.length === 6 ? `Code entered: ${code}` : "Enter the 6-digit code we sent you."}
      </p>
    </div>
  )
}

API reference

PropTypeDefaultDescription
lengthnumber6Number of characters.
valuestring—Controlled value.
onValueChange(value: string) => void—Called whenever the value changes.
onComplete(value: string) => void—Called when every box is filled, e.g. to submit.
alphanumericbooleanfalseAccept letters as well as digits.
labelstring"Verification code"Accessible name for the group.
disabledboolean—Disable all boxes.

Only the props above.

Requirements

  • React 19 and Tailwind CSS v4, with a cn helper at @/lib/utils.

Customization

  • Submit automatically with onComplete, but keep a submit button for people who type slowly.
  • Letters are converted to upper case when alphanumeric is on.

Accessibility

  • The boxes form a labelled group, and each box is named “Character n of 6”.
  • Arrow keys move between boxes, Backspace deletes and moves back, and pasting a code fills every box.
  • The first box uses autocomplete="one-time-code", so phones can fill codes from SMS.

Troubleshooting

SMS autofill doesn’t appear.
The OS offers it only when the field is in a page served over HTTPS and the SMS follows the platform’s one-time-code format.
Unknown registry "@venusui"
Your shadcn CLI couldn’t find the namespace in the shadcn registry index. Use the latest CLI (npx shadcn@latest), install by URL, or register it with its address: npx shadcn@latest registry add @venusui=https://venusui.com/r/{name}.json.
No components.json found
Run npx shadcn@latest init in your project first.
Loading preview

A text field whose label sits inside and floats above on focus or when filled.

Loading preview

A number field with minus and plus buttons, clamped to a range.

Loading preview

A lock-screen passcode keypad that shakes on a wrong code and unlocks on the right one.