Skip to content

shadcn.io is an independent project built on shadcn/ui

Free

OTP Code Dialog for Svelte

A verify-email dialog with six code slots, a Resend link, and Verify kept off until every digit is filled.

UI library: Ark UI

Enter Code opens Verify your email. The description says a 6-digit code was sent. Six slots sit under Verification code, with Resend under them. Verify stays off until all six digits are in.

Use it to collect a code without leaving the page. Resend does nothing until you wire it. Account details beside the code fit a Sheet. In Svelte, Ark UI does not check the code.

Preview

Preview width

Installation

MCP · Pro
Make your AI a shadcn expert
Your agent installs components, builds pages and restyles your app from one prompt, in Claude Code, Cursor or VS Code.
Part of Pro

Anatomy

Dialog anatomy: content, title, description, close, footer

Usage

<Dialog><DialogTrigger>{#snippet asChild(props)}<Button {...props()} variant="outline">Enter Code</Button>{/snippet}</DialogTrigger><DialogContent class="sm:max-w-md"><DialogHeader><DialogTitle>Verify your email</DialogTitle><DialogDescription>We've sent a 6-digit code to your email address. Please enter it below.</DialogDescription></DialogHeader><Field><FieldLabel>Verification code</FieldLabel><div class="flex justify-center"><InputOTP onValueChange={handleValueChange} value={value}><InputOTPGroup><InputOTPSlot index={0} /><InputOTPSlot index={1} /><InputOTPSlot index={2} /><InputOTPSlot index={3} /><InputOTPSlot index={4} /><InputOTPSlot index={5} /></InputOTPGroup></InputOTP></div><FieldDescription class="text-center">Didn't receive the code?{" "}<Button class="h-auto p-0" variant="link">Resend</Button></FieldDescription></Field><DialogFooter><Button disabled={!complete}>Verify</Button></DialogFooter></DialogContent></Dialog>

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 an array of digits, from onValueChange.

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.

API Reference

Dialog

No extra props in this demo. The rest is on the Dialog page.

Button

Sets props, variant="outline", variant="link" and disabled={!complete}. The rest is on the Button page.

Field

No extra props in this demo. The rest is on the Field page.

Input OTP

Sets onValueChange={handleValueChange}, value={value}, index={0}, index={1}, index={2} and index={3}. The rest is on the Input OTP page.