Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Dialog examples · Standard

OTP Code Dialog for React

A verification dialog with a six-digit code field and a Verify button that waits for every digit.

Framework
UI library

A one-time code in a plain text box feels clumsy. This React dialog uses shadcn.io's Input OTP with six slots that move focus as people type, and keeps Verify disabled until the code is complete. It's built on shadcn.io's Dialog on Base UI.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

FAQ

Should it submit on the sixth digit?

Only if verification is instant and errors are rare. Otherwise enable Verify at six digits, as here, and let Enter submit.

Can people paste the code?

Yes. Pasting a code fills the slots at once, so people can copy it from an email or a text message.

How is the value read?

The field is controlled, and Verify checks that all six digits are there. The value is a string, from onChange, with maxLength of 6.

Should Resend have a cooldown?

Yes: disable it for 30 to 60 seconds after a send and show the countdown. Resend is a link-style Button here; wire it to your request.

How do I handle an expired code?

Your server decides. Show the error in the field and offer to resend, and keep the dialog open.

Should the digits be masked?

No. Codes are short-lived, and people need to check what they typed.