Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Input OTP examples · Standard

OTP with Multiple Separators Input OTP for React

A six-digit code field split into three pairs by two separators.

Framework
UI library

Some codes are printed in pairs, like 12-34-56. This example splits six slots into three InputOTPGroup blocks of two with an InputOTPSeparator between each, so the field matches the code's printed shape and is easier to copy by eye.

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 pairs made?

Three InputOTPGroup parts with two slots each, and an InputOTPSeparator between them. The separators are visual only; the code is still six characters.

How do the slot indexes work across groups?

index counts through the whole code, 0 to 5: 0 and 1 in the first pair, 2 and 3 in the second, 4 and 5 in the third. Don't restart it in each group.

When should I group in pairs?

When your codes are shown in pairs, in an SMS, an email or an authenticator. Matching the field to the printed format makes the code quicker to copy; for codes shown without grouping, one group of six is clearer.

Can the separator be something other than a minus?

InputOTPSeparator renders a minus icon with role separator. For a different mark, render your own element between the groups, hidden from screen readers since it isn't part of the code.

What sets the number of digits?

maxLength sets the length; render one InputOTPSlot per character.

Does pasting fill all the pairs?

Yes. A pasted code fills the slots in order across every group, ignoring the separators.