Skip to content

OTP Verification Page for React

A glass OTP verification page for React that submits on the last digit, shakes on a wrong code and counts down to resend.

npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/otp-verification.json

Check your inbox

Enter the 6-digit code we sent to maya@example.com.

Didn't get it? Resend in 30s

Verify a code

The correct code is 123456.

Check your inbox

Enter the 6-digit code we sent to you@example.com.

Didn't get it? Resend in 15s

Files to copy

10 folders · 13 files · 4 packages
From theme/src/
  • blocks/{otp-verification.tsx, icons.tsx}
  • components/button/
  • components/glass-card/
  • components/otp-input/
  • components/spinner/
  • components/status-icons/
  • hooks/{use-latest.ts, use-magnetic.ts, use-media-query.ts, use-preferences.ts}
  • motion/{gate.ts, light-follower.ts, tokens.ts}
  • lib/{cn.ts, form.ts, heading.ts, state-light.tsx}
  • styles/
shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/otp-verification.jsonRegistry item: otp-verification. The styles need the Tailwind v4 glass UI setup.
Packages
pnpm add @base-ui/react clsx motion tailwind-merge

Unlock variant

variant="unlock" puts a padlock inside a ring that fills with every digit. A right code opens the lock and floods the card with light; a wrong code rattles it and clears the digits. The correct code is 482913.

Check your inbox

Enter the 6-digit code we sent to the phone ending in 47.

Didn't get it? Resend in 15s

Four digits, with a Continue button

length changes the number of slots; onContinue adds a Continue button once the code is accepted. The correct code is 4821.

Check your inbox

Enter the 4-digit code we sent to +1 ••• ••• 0142.

Didn't get it? Resend in 30s

Props

PropTypeDefaultDescription
destinationReactNode"your email"Where the code was sent, shown in the description (ReactNode, default "your email").
lengthnumber6Sets the number of digits (number, default 6).
onVerify (required)(code: string) => boolean | Promise<boolean>NoneReturn true if the code is correct. Throwing counts as a wrong code.
onResend(() => void | Promise<void>)NoneCalled when the person asks for a new code. Without it the resend control still resets the field.
onContinue(() => void)NoneShows a "Continue" button once the code is accepted.
resendAfternumber30Seconds before "Resend" becomes available (number, default 30).
autoFocusbooleantrueFocus the first digit on mount (boolean, default true). Turn it off when the block is not the main task on the page.
labelsPartial<OtpVerificationLabels>defaultOtpVerificationLabelsEvery other string, for translation: labels={{ title: "…" }}; omitted keys keep the English of defaultOtpVerificationLabels. All 15 keys of OtpVerificationLabels are listed in the key table under the props table.
headingLevelHeadingLevelOption2Level of the title heading (1 to 6, default 2); set it to fit the page's outline. "none" renders a paragraph with no heading role (for an example).
classNamestringNoneAdds extra classes to the outer glass card (string).
variant"default" | "unlock""default""default" (the plain card) or "unlock" ("default" | "unlock", default "default"): a padlock inside a progress ring that fills with every digit and spins while the code is checked. A right code closes the ring in green, opens the lock, bursts sparks, floods the card with light and shows a "Verified" badge; a wrong code rattles the lock and clears the digits. Reduced motion swaps all of it for an instant change.
OtpVerificationLabels keys and English defaults (15)
Pass any key in labels; the rest keep the defaults of defaultOtpVerificationLabels.
KeyEnglish default
titleCheck your inbox
titleVerifiedYou're verified
description(length, destination) => ( <> Enter the {length}-digit code we sent to {destination}. </> )
descriptionVerifiedYour code was accepted. You can continue.
codeLabelVerification code
errorThat code didn't match. Try again.
incomplete(length) => `Enter all ${length} digits.`
successCode accepted.
resentWe sent you a new code.
verifyVerify code
continueContinue
resendPromptDidn't get it?
resendIn(s) => `Resend in ${s}s`
resendResend code
verifiedBadgeVerified

Keyboard

KeysAction
0–9Type or paste the digits; focus advances by itself.
BackspaceStep back to the previous digit.
Tab, then Enter/Spaceon VerifyVerify (the code also verifies as soon as the last digit is in). Verify pressed early moves focus to the first empty slot and explains.
Enter/Spaceon ResendAsk for a new code, once the countdown is over.

Accessibility

  • The digit field is named by codeLabel; wrong-code, incomplete, resent and success messages share one polite live region.
  • The resend countdown is text, not color only.
  • After success focus moves to Continue (or the heading).

All exports on this page

  • OtpVerification — A one-time-code card: digit slots, a verify button, a resend countdown and a success state.
  • defaultOtpVerificationLabels — The English OtpVerificationLabels used when labels is omitted; a partial labels prop is merged over it.

When to use the OTP verification page

  • Use OtpVerification as an OTP verification UI for the email or SMS confirmation step after sign-up, where the visitor types a six-digit code and, once it is accepted, sees a Continue button if you pass onContinue. Use it as the 2FA code screen after a password step.
  • Use it for a two-factor sign-in step in an admin panel, setting length to 4 or 8 to match your provider and resendAfter to the cooldown your backend enforces.
  • Use it to confirm a sensitive action such as changing a payout account, with destination naming the phone number or address so the person knows where to look.
  • Skip it when you only need the bare digit field inside your own layout; the OtpInput component gives you the slots without the card, verify button and resend countdown.
  • Pair it with GlassLogin or AuthSplit for the step that comes before it, and with Toast if your flow needs extra confirmation after Continue.

Frequently asked questions

20 blocks pages in all: browse them on All blocks.

By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .