Input otp
Separate boxes for a one-time code.
In Dense data
See it live
npm run storybookWhen to use it
In Dense data: A fixed-length one-time code sent by text or email. Not for passwords or any other value.
- Use it when: A short code sent by text or email, typed or pasted.
- Not when: Passwords or any value that is not a fixed-length code.
Instead:
- Input: Any other short value.
Words
- Lead with the object, then the state: "Alert 2041 contained."
- Use numbers, not words for numbers.
- One verb per button. No "please", no exclamation marks.
- Use: Investigate, Filter, Assign, Escalated, Resolved. Avoid: Oops, Awesome, Please, Simply.
The labels components use, from the voice tokens:
content.action.commit: Savecontent.action.cancel: Cancelcontent.action.destroy: Deletecontent.action.retry: Retrycontent.action.empty-action: Change filters
See Voice and tone for the whole voice.
Accessibility and keyboard
Test before you ship:
- Screen readers hear one field with a label, and pasting the whole code works. undefined
Use it in code
npx open-ds add input-otp
The component reads only component keys and semantic tokens, so it follows the brand and mode on <html>.
Tokens it reads
Input otp reads 12 tokens of its own, each an alias of a semantic token. Each row is one part: its own token, the semantic it aliases, and the value it ends at. Change a semantic and every component that reads it follows; override one of Input otp's tokens to change Input otp alone.
Dense data decides what changes when you switch theme. Here a switch changes colors only, so the marked rows differ between light and dark; everything else holds steady.
| Part | Its token and the semantic it aliases | Value |
|---|---|---|
| Input otp | ||
| Gap | component.input-otp.gapspace.gap.defaultvar(--input-otp-gap) | space.8:0.5rem |
| Disabled opacity when disabled | component.input-otp.disabled-opacityopacity.disabledvar(--input-otp-disabled-opacity) | opacity.40:0.4 |
| Height | component.input-otp.heightsize.iconvar(--input-otp-height) | size.16:1rem |
| Fill Changes with theme | component.input-otp.backgroundcolor.text.primaryvar(--input-otp-background) | Lightslate.light.900:#161B23Darkslate.dark.900:#F7F8FA |
| Speed | component.input-otp.durationmotion.duration.feedbackvar(--input-otp-duration) | duration.fast:120ms |
| Slot | ||
| Border Changes with theme | component.input-otp.slot.bordercolor.border.strongvar(--input-otp-slot-border) | Lightslate.light.500:#6B7585Darkslate.dark.400:#969FAD |
| Text size | component.input-otp.slot.font-sizetype.body.font-sizevar(--input-otp-slot-font-size) | font.size.14:0.875rem |
| Shadow | component.input-otp.slot.shadowelevation.cardvar(--input-otp-slot-shadow) | shadow.none |
| Border invalid Changes with theme when invalid | component.input-otp.slot.border-invalidcolor.status.dangervar(--input-otp-slot-border-invalid) | Lightred.light.600:#C42B2BDarkred.dark.600:#F28B8B |
| Border 2 Changes with theme | component.input-otp.slot.border-2color.border.focusvar(--input-otp-slot-border-2) | Lightviolet.light.600:#4B3FD9Darkviolet.dark.600:#A9A3F6 |
| Focus ring Changes with theme | component.input-otp.slot.focus-ringcolor.border.focusvar(--input-otp-slot-focus-ring) | Lightviolet.light.600:#4B3FD9Darkviolet.dark.600:#A9A3F6 |
| Focus ring invalid Changes with theme when invalid | component.input-otp.slot.focus-ring-invalidcolor.status.dangervar(--input-otp-slot-focus-ring-invalid) | Lightred.light.600:#C42B2BDarkred.dark.600:#F28B8B |
| From the system | ||
| Edge Changes with theme | color.border.default straight from the system, through --border | Lightslate.light.200 · #DDE2EADarkslate.dark.100 · #262D38 |
| Corner | radius.control straight from the system, through --radius-md | radius.2 · 0.125rem (2px) |