Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Input OTP examples · Standard

Standard OTP Input Input OTP for React

A six-digit one-time code field split into two groups of three.

Framework
UI library

The classic verification code field. This example renders six InputOTPSlot boxes in two InputOTPGroup blocks of three with an InputOTPSeparator between them, matching how codes like 123-456 arrive in messages. Focus moves from box to box as people type, and pasting a whole code fills every box.

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

How are the two groups made?

Each InputOTPGroup joins its slots into one block, and InputOTPSeparator draws a minus between blocks. The separator isn't a character, and index counts straight through the groups, 0 to 5.

What sets the number of digits?

maxLength sets the length; render one InputOTPSlot per character.

How does focus move between the boxes?

Typing a character fills the current box and moves to the next; Backspace clears and moves back, and the arrow keys move between boxes. Pasting a full code fills them all at once.

Does it accept letters?

Yes: without a pattern, any character is accepted. Pass a digits-only pattern, as the Numeric Only example does.

Why do the slots have bg-background?

So the boxes stay solid on a muted or tinted surface, such as a card or the preview. Drop the class when the field sits on the page background.

How do I read the code?

Pass a value and a change handler, as the Controlled example does, or read it from the form when it's submitted. The value is one string, and onChange receives the next string.