React OTP Input
A React OTP input with one slot per digit, paste and SMS autofill, and Motion feedback: digits pop in, errors shake and success ripples.
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/otp-input.jsonVerify your number
We sent a code to the phone ending in 47.
OtpInputdefaultOtpInputLabels
Using it in a form? See the react-hook-form and zod recipe.
Basic
Enter the code we sent you.
import { OtpInput } from "@/components/sheenui/otp-input/otp-input";
// Package build (after the first npm release, or a packed tarball): import { OtpInput } from "@sheenui/theme";
export function Example() {
return (
<OtpInput length={6} label="Verification code" description="Enter the code we sent you." />
);
}Files to copy
5 folders · 7 files · 4 packages
- From
theme/src/ components/otp-input/hooks/{use-latest.ts, use-media-query.ts, use-preferences.ts}motion/tokens.tslib/{cn.ts, form.ts, state-light.tsx}styles/
- shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/otp-input.jsonRegistry item: otp-input. The styles need the Tailwind v4 glass UI setup.- Packages
pnpm add @base-ui/react clsx motion tailwind-merge
Status feedback
The correct code is 123456. Anything else shakes the field.
import { useState } from "react";
import { OtpInput, type OtpStatus } from "@/components/sheenui/otp-input/otp-input";
// Package build (after the first npm release, or a packed tarball): import { OtpInput, type OtpStatus } from "@sheenui/theme";
export function Example() {
const [value, setValue] = useState("");
const [status, setStatus] = useState<OtpStatus>("idle");
return (
<OtpInput
grouped
value={value}
status={status}
errorMessage="That code didn't match. Try 123456."
successMessage="Code verified."
// Only clear the status once the code is incomplete again: onValueChange also fires for the
// last digit, and an unconditional reset there would undo onComplete's result.
onValueChange={(v) => { setValue(v); if (v.length < 6) setStatus("idle"); }}
onComplete={(v) => setStatus(v === "123456" ? "success" : "error")}
/>
);
}Success effect
Type any 6 digits. "seal" (the default) scans the slots with light, folds them into one glass seal and draws a check; "ring" ripples a ring round each slot; "none" only recolours them. Reduced motion fades the seal in and skips the rest.
import { OtpInput } from "@/components/sheenui/otp-input/otp-input";
// Package build (after the first npm release, or a packed tarball): import { OtpInput } from "@sheenui/theme";
export function Example() {
return (
<OtpInput
successEffect="seal" // "seal" (default) | "ring" | "none"
status="success"
defaultValue="123456"
successMessage="Code verified."
/>
);
}Masked, 4 digits
import { OtpInput } from "@/components/sheenui/otp-input/otp-input";
// Package build (after the first npm release, or a packed tarball): import { OtpInput } from "@sheenui/theme";
export function Example() {
return (
<OtpInput length={4} mask label="PIN" />
);
}Props
OtpInputLabels keys and English defaults (1)
Keyboard
Accessibility
- The first slot is named by the label and the others "Digit n of N"; autoComplete="one-time-code" lets phones suggest the code.
- The error and success messages sit in a polite live region; the seal and its sparks are decorative (aria-hidden), so the announcement is the same for every successEffect.
- Slots are at least 44 px wide and 48 px tall with a 3:1 border (WCAG 1.4.11).
All exports on this page
OtpInput— One-time code input: a row of single-digit slots for SMS, email and authenticator codes.defaultOtpInputLabels— The English OtpInputLabels used when labels is omitted; a partial labels prop is merged over it.
When to use the OTP input
- Use OtpInput as a verification code input in React on a two-factor sign-in or phone verification screen, where an SMS or authenticator code of fixed length arrives and people type or paste it. Treat it as an input-otp alternative when you want styled, labeled code slots instead of a headless primitive.
- Use onComplete to verify the code the moment the last digit lands, and set status to error or success to shake the field or play a soft ripple with a message.
- Use grouped for a six digit code shown as 3 + 3, or mask when the code is sensitive and should not be readable over someone's shoulder.
- Skip it when the value is not a fixed-length numeric code. Use Input for an email or a recovery phrase, including a password with a show button in its trailing slot.
- Pair it with Button for a resend action, Alert for a rate-limit message, and the OTP verification block, which already assembles these pieces on one screen.
SheenUI OtpInput or input-otp?
input-otp is a headless one-time-code library. SheenUI's OtpInput is built on Base UI's OTP field and arrives styled: glass slots, paste and SMS autofill, grouped and mask options, and error and success feedback through the status prop. Use input-otp if you want to draw every slot yourself; use this one if you want a finished, accessible field to copy.
Frequently asked questions
Related pages
67 components pages in all: browse them on All components.
By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .