One-time code input on input-otp: the focus rim travels cell to cell, a wrong code is refused with one kick, dots count the attempts left, a lockout counts down on a ring and a verified code wraps the row in one capsule.
TypeType
Environment · Production
Reveal secret value
DATABASE_URLHidden
••••••••••••••••••••Hidden value
Enter the 6-digit code from your authenticator app.
3 of 3 attempts left
otp-input · , lively
otp-input-demo.tsx
When to use
Use for a one-time code of 4 to 8 characters. Your app checks the code and passes status back; it also shows attempts left and a lockout countdown. Presets: boxes, grouped, pin. Built on input-otp.
When not to use
For a long token or recovery code use Text Field. For fixed-format identifiers such as IBAN use Masked Input.
Use it to enter a one-time code of 4 to 8 characters: sign-in verification, email or phone
confirmation, or a PIN that approves a payout. One real input reads the code, so paste,
autofill (autocomplete="one-time-code") and screen readers work; the cells are its picture.
For a free-form token or a long recovery code, use a plain text field.
The moment: the field notices you. Every empty cell holds a small placeholder ball. When you focus
the field, or a code lands from a paste or autofill, the balls hop once in a wave that spreads from
your cell, and the ball in the active cell stretches up into the caret: a circle that becomes a
thin capsule. On success the focus rim wraps the whole row and rounds into one capsule.
The motion follows the three beats. Focus charges: the rim fades onto the active cell with its
leading edge leaning 2 px toward the next cell, and the active ball stretches up into the caret. A
key press pushes the caret back down into a ball. Then the action: the digit drops onto that
ball, the cell's floor takes the hit, and the rim's leading edge is thrown to the next cell while
its trailing edge follows a little slower, so for a beat it covers both cells. It settles as
the trailing edge catches up and the next ball stretches into the caret. A pasted code arrives as a
cascade, the hop wave carries on through the cells still empty, and the rim crosses every cell in
one throw. A wrong code turns the rims red left to right, the rim goes home to the first cell and
the row is refused with one kick toward the start: a push and a return on the calm spring, never a
shake or a bounce. With attemptsLeft, the dot of the attempt just used lets its fill go (the empty
ring stays), and the last one left turns red. Out of attempts, lockedUntil disables the input
and a ring empties clockwise beside "Try again in 0:19"; when it closes, onUnlock fires and the
dots refill left to right. Digits sit at the optical centre of their cell. Temperament only
changes how high the balls hop, how far the rim stretches and how much it overshoots: at calm the
hop is a 2 px nod, at playful a clear jump with a squash on landing. At rest the three look the same.
import { OtpInput } from "@/components/ui/otp-input"export function VerifyPhone() { return <OtpInput aria-label="Verification code" onComplete={(code) => verify(code)} />}
The app owns the result. Pass it back with status (idle, verifying, success, error) and
an errorMessage; typing after an error or a success returns the look to idle. A
successMessage shows under the cells with a traced check, like the TextField's valid state.
The app counts attempts; the component shows them. attemptsLeft with maxAttempts draws one dot
per attempt under the cells (read with the input as "2 of 3 attempts left"). When none are left,
pass the lock's end as lockedUntil (a Date or epoch ms) and reset in onUnlock. lockDuration
(seconds) is the full length, so the ring starts full; without it the ring starts from the time
left when the lock is first seen. Read the clock in an event or effect, never during render.
lockedUntil={null} reserves the message line without locking, so nothing moves when a lock starts.
The server always enforces the limit; the component only shows it.
Unmasked inputs set autocomplete="one-time-code", so iOS and Android offer the code from the SMS
above the keyboard. On Chrome for Android you can also read it with the WebOTP API when the SMS ends
with @your.domain #123456:
useEffect(() => { if (!("OTPCredential" in window)) return const abort = new AbortController() navigator.credentials .get({ otp: { transport: ["sms"] }, signal: abort.signal } as CredentialRequestOptions) .then((credential) => { const code = (credential as { code?: string } | null)?.code if (code) setCode(code) // lands as a paste: the cells fill in a cascade }) .catch(() => {}) return () => abort.abort()}, [])
<OtpInput value={code} onValueChange={setCode} onComplete={submit} status={status} errorMessage="That code is not valid. Check the message and try again."/>
The preset picks the layout and nothing else: boxes (6 cells in a row, default), grouped
(3 + 3 with a separator dot, change it with groups) and pin (4 masked cells with a Show
toggle). length, groups and masked override the preset. size is sm, md or lg. Allowed
characters come from pattern (digits by default; REGEXP_ONLY_CHARS and
REGEXP_ONLY_DIGITS_AND_CHARS are re-exported). Set the motion character with temperament
(calm, lively, playful) or the app-wide MotionKitProvider. Announcements and the Show
toggle text are changed with labels (attempts and locked are functions, for plurals and the
time).
We sent a code to new.address@example.com. It expires in 10 minutes.
204917
That code doesn't match. Check the latest email.
otp-input · , lively
otp-input-grouped-demo.tsx
preset="grouped" splits the code 3 + 3 with a separator dot; the focus rim stretches over it on
the hop between groups. The demo shows the error state with a message under the cells.
preset="pin" draws each digit as a ball and adds a Show toggle. Use it before payouts or other
destructive actions. The rim, the caret and the success capsule work the same way. The demo
counts attempts: 0000 is the wrong PIN.
Three wrong PINs lock approvals for 5 minutes. An admin can reset it sooner.
0 of 3 attempts left
otp-input · , lively
otp-input-locked-demo.tsx
lockedUntil disables the input and shows a ring that empties clockwise beside "Try again in
m:ss". Plain disabled greys the cells and hides the focus rim and the caret, with no
countdown.
One real <input> from input-otp reads the code, with autocomplete="one-time-code" (off when
masked) and a numeric keyboard on touch. The cells, focus rim, caret, separators and placeholder
dots are aria-hidden; assistive technology reads the input's value.
Give it a name with a <label htmlFor> and id, aria-labelledby or aria-label. Without one
it falls back to "Verification code, 6 digits" ("characters" when masked).
status="error" sets aria-invalid and links errorMessage through aria-describedby.
status="verifying" sets aria-busy and makes the input read-only.
A polite live region announces "Verifying", "Code accepted" (or your successMessage), the error
message, and once "Too many attempts" when a lockout starts. The ticking countdown is not live
(it would talk every second): it is linked to the input with aria-describedby, and so are the
attempts left ("2 of 3 attempts left"). The dots and the ring are aria-hidden.
While locked the input is disabled. The last attempt's dot is destructive, but the count is
always in text too, never color alone.
The travelling rim is the focus indicator: a 2 px ring rim plus a 5 px halo, never off while
the input has focus and never half-drawn, even mid-travel. The caret in the empty active cell is
a second cue. Digits stay foreground in every state, including error.
On small screens the gaps close to 4 px, then cells narrow to 32 px (six sm cells fit a 224 px
row); only a narrower container takes them further, with a smaller radius so they stay tiles.
Cells are 48 px or more tall and the whole group is one target, so nothing clips.
Rim, success and error colors come from ring, destructive and success (shipped in cssVars
for light and dark).
With reduced motion (the OS setting, or MotionKitProvider reducedMotion="always") the focus rim
still travels, because a teleporting position is harder to follow, but both edges move together in
the short fade time: no stretch, no nudge. The placeholder balls do not hop, the caret takes its shape in the fade time, digits fade in place,
pasted digits fade together, error rims turn red at once, the refusal kick is skipped, attempt dots
fade instead of shrinking, the lockout ring steps with the clock, the success check is drawn whole
and the success capsule forms in the fade time. Every state is still a complete picture: the focus rim, the caret, the red rims and the
capsule are all present at rest.
Our code (the component plus the MotionKit helpers it installs) is about 8.5 kB gzip. It does
not count the peers, which your app may already ship: motion and input-otp (1.5, about
4 kB gzip minified).
Cell and rim positions are computed from fixed geometry, not measured per frame; only the
component's width is observed (a ResizeObserver) so cells can narrow on small screens.
One absolutely positioned element draws the focus rim: it moves with transform and its width
is the one animated layout property (both edges are motion values, so React does not re-render
while it travels). Digits and the hop animate transform and opacity only; the 2 px caret's height and radius are
the one other animated property, on an element too small to cost a layout.
There are no loops: status="verifying" is a still state with aria-busy. The lockout ticks
four times a second on the wall clock (not the time scale) and only its own line re-renders; it
stops when the lock ends. Nothing is lazy-loaded.
Technical sheet
Motion
calm
260 ms · bounce 0
lively
400 ms · bounce 0.3
playful
540 ms · bounce 0.45
Main spring of each temperament. Set it with the temperament prop or MotionKitProvider; the default is lively.
Size
Not measured yet · budget 15.0 kB gzip
Component and MotionKit helpers; excludes react, react-dom, motion.
Dependencies
input-otp
motion · peer
Triggers
typing, keyboard focus, a value change
Reduced motion
The rim still travels, both edges together in the fade time; balls do not hop, digits fade in place, error rims turn red together with no kick, attempt dots fade, the lock ring steps with the clock.
Keyboard
0-9 (or allowed characters)
Fills the active cell; the focus rim stretches to the next
Backspace
Clears the previous cell; the focus rim travels back one cell
Delete
Clears the active cell
Arrow Left / Arrow Right
Moves the active cell
Home / End
Jumps to the first or the last filled cell
Mod+V
Pastes a code: the cells fill in a cascade
Enter
Submits the surrounding form
Tab / Shift+Tab
Leaves the control
Browsers
Last 2 versions of Chrome, Edge, Firefox and Safari (iOS 16.4+)