Back to elements
Element•Premium

OTP Input

A one-time-code input with separate slots, paste and SMS autofill support, a blinking caret, masked mode, and success and error states.

Check your inbox

Enter the 6-character code we sent to jane@company.com

Didn’t get it?

Customize

Overview

About the OTP Input

A one-time-code input with separate slots, paste and SMS autofill support, a blinking caret, masked mode, and success and error states. It is delivered as editable TypeScript for React. Tailwind CSS is not required; the component's visual CSS is embedded in its TypeScript source. Its focused API can be adapted to your own content and visual system.

Usage

When to use it

  • Sign-in, two-factor, and email verification screens that ask for a short code.
  • Checkout or account recovery flows where codes arrive by SMS or email.

What’s included

Files in the product ZIP

OTP Input source

components/otp-input.tsx

Editable React and TypeScript component source.

Working example

examples/example.tsx

A minimal import and render example that matches the packaged API.

Installation guide

README.md

Manual ZIP installation, styling, compatibility, asset, and usage notes.

Usage

Import and render

Copy the packaged source to the documented path, then use the public API shown below.

Import
import { OtpInput } from "@/components/otp-input";
Minimum example
export default function VerifyCode() {
  return <OtpInput length={6} onComplete={(code) => console.log(code)} />;
}

Props

Component API

PropTypeDefaultDescription
lengthnumber6Number of code slots.
valuestring—Controlled code value.
defaultValuestring""Initial value when uncontrolled.
onChange(value: string) => void—Called with the sanitized value on every change.
onComplete(value: string) => void—Called once every slot is filled.
status"idle" | "success" | "error""idle"Visual state; error shakes the slots, success highlights them.
mode"numeric" | "alphanumeric""numeric"Characters allowed in the code.
groupSizenumberlength / 2Slots per group before a separator.
maskbooleanfalseRender dots instead of characters.
accentstring"#a78bfa"Focus and caret color.
classNamestring""Additional root class names.

Also accepts native input attributes such as name, autoFocus, and disabled.

Compatibility

Verified project setup

  • ReactLoom's preview is tested with Next.js 16.3.8 App Router, React 19.2.8, TypeScript 5.9.3, and Tailwind CSS 4.3.3. This describes the store environment, not the product's minimum requirements.
  • This interactive component includes the "use client" directive and must remain behind a Client Component boundary in the Next.js App Router.
  • Tailwind CSS is not required; the component's visual CSS is embedded in its TypeScript source.
Images
No image files are included or required by the packaged component.
Fonts
No font files are included. The component uses system font fallbacks unless your app supplies a matching font.

Installation

Add it to your project

Download the OTP Input ZIP, place the source file at src/components/otp-input.tsx, and copy the example into your own page or feature folder.

Target path

src/components/otp-input.tsx

No additional npm runtime packages are required beyond the React host; follow the styling requirements below.

Styling requirements

  • Tailwind CSS is not required by this component.
  • All component styles are embedded in components/otp-input.tsx.