OTP field
Segmented one-time-code entry that advances on type, steps back on backspace and fills every box from a single paste.
Live preview
Source
The exact file rendered in the preview above.
components/demos/otp-field.tsx
components/ui/otp-field.tsx
Demo source — adapt to your project. Foundry is not published as a package.
Usage
For emailed or texted verification codes. Everything people expect and almost every implementation gets wrong is handled here — most importantly, pasting a full code fills all six boxes rather than dropping six characters into the first.
- `autoComplete="one-time-code"` on the first box lets iOS and Android offer the SMS code.
- Arrow keys move between boxes without editing; Backspace on an empty box clears the previous one and steps back.
- Validate on completion, not on every keystroke.
Variants and states
Every entry below is a genuine difference in behaviour or layout, and every one of them is visible in the preview above.
- Six digits
- Invalid
- Complete
- Disabled
Accessibility
- Per-box labels
- Each input is labelled "Digit n of 6", so a screen reader user always knows where they are.
- Group
- The set is wrapped in a labelled `role="group"`.
- Errors
- The error is described once, on the first box, rather than repeated six times.
Foundry implements published ARIA patterns and is tested against them. No WCAG certification is claimed — see the accessibility documentation for what is and is not covered.
Related
All componentsVerification code
An OTP flow with a resend cooldown and a failure state that does not clear the entered code.
intermediateFeatured5 variantsField
The accessibility contract shared by every form control — label, help text, error, success and the ARIA wiring that connects them.
intermediateFeatured7 variantsMagic link
A one-field sign-in whose success state names the address and offers a correction path.
starter4 variants