Back to Components

OTP Input

A self-contained OTP/verification-code input with four independently functional variants (bordered squares, underline, connected capsule, filled tiles). A Framer Motion spring drives the focus indicator between slots using real measured positions.

Preview

Installation

Install the component using the CLI.

npx shadcn@latest add https://shreyashtech.me/r/otp-input.json

Usage

Import the component:

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

Use it in your code:

<OtpInput length={6} variant="classic" />

Props

PropertyTypeDefaultDescription
lengthnumber6Number of OTP digits/slots.
variant"classic" | "underline" | "pill" | "filled"all fourRender only this single variant instead of the full four-card demo.
valuestring-Controlled value. Pass with onChange to control the input externally.
onChangefunction-Called with the joined digit string whenever any slot changes.
onCompletefunction-Called once with the full code when every slot is filled.
disabledbooleanfalseDisable every slot.
autoFocusbooleantrueFocus the first slot on mount.
theme"light" | "dark" | "system"systemColor theme for borders, digits, and the active indicator.
classNamestring-Extra classes applied to the outermost wrapper.