Skip to main content

Input otp

Separate boxes for a one-time code.

In Accessible first

See it live​

Start Storybook to see it live: npm run storybook

When to use it​

In Accessible first: A short code sent by text or email, typed or pasted. Not passwords or values of any length.

  • 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​

  • Use common words. Explain any term you must use.
  • One idea per sentence. Put the action first.
  • Never blame the person.
  • Use: Continue, Change, Start, You. Avoid: Invalid, Utilise, Submit, Error code.

The labels components use, from the voice tokens:

  • content.action.commit: Continue
  • content.action.cancel: Go back
  • content.action.destroy: Delete
  • content.action.retry: Try again
  • content.action.empty-action: Start a new application

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.

Changes with theme

Accessible first 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.

PartIts token and the semantic it aliasesValue
Input otp
Gapcomponent.input-otp.gapspace.gap.defaultvar(--input-otp-gap)space.16:1rem
Disabled opacity
when disabled
component.input-otp.disabled-opacityopacity.disabledvar(--input-otp-disabled-opacity)opacity.50:0.5
Heightcomponent.input-otp.heightsize.iconvar(--input-otp-height)size.20:1.25rem
Fill
Changes with theme
component.input-otp.backgroundcolor.text.primaryvar(--input-otp-background)Lightgray.light.900:#141414Darkgray.dark.900:#F7F7F7
Speedcomponent.input-otp.durationmotion.duration.feedbackvar(--input-otp-duration)duration.moderate:200ms
Slot
Border
Changes with theme
component.input-otp.slot.bordercolor.border.strongvar(--input-otp-slot-border)Lightgray.light.500:#595959Darkgray.dark.500:#949494
Text sizecomponent.input-otp.slot.font-sizetype.body.font-sizevar(--input-otp-slot-font-size)font.size.19:1.1875rem
Shadowcomponent.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)Lightblue.light.600:#0B4FC0Darkblue.dark.600:#8AB4F8
Focus ring
Changes with theme
component.input-otp.slot.focus-ringcolor.border.focusvar(--input-otp-slot-focus-ring)Lightblue.light.600:#0B4FC0Darkblue.dark.600:#8AB4F8
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
Lightgray.light.200 · #D6D6D6Darkgray.dark.100 · #222222
Cornerradius.control
straight from the system, through --radius-md
radius.6 · 0.375rem (6px)