Skip to content

OTP field

The one-time code a sign-in asks for, as a row of lit digit windows — the Field's recessed well cut into six screens, in the LCD voice. Built on Base UI's OTP Field: a pasted code fills the row, arrow keys and Backspace walk it, and the phone can offer the code from an SMS. Composes var(--echo-*).

Feel Six lit windows. The one you're on sinks into the panel, so the press travels along the row as you type, each digit lands as a small strike, and the finished code runs a ripple down the row.

Preview

Sent to your phone.

Or let the agent fetch it: get_component("otp-field") on the Echo MCP server.

Installation

npx echo-ui-cli add otp-field

First time? Run npx echo-ui-cli init once — it sets the project up, and add refuses to run before it.

At a glance

Version
0.3.0
Weight
909 B · 43.2 KB with what it imports · 1.1 KB of CSS (minified and gzipped; React not counted)
Needs
@base-ui/react, gsap, size (Echo, brought with it)
Keyboard
typing a digit moves to the next window; Backspace and the arrow keys walk the row, and a pasted code fills it.
Reduced motion
The windows don't sink, take strikes or ripple; only the focus edge fades.

Usage

tsx
import { OtpField } from "@/echo/otp-field";

<OtpField label="Verification code" onComplete={submit} />

Composition

OtpField

Examples

Six digits

The default.

tsx
<OtpField label="Verification code" onComplete={submit} />

Four digits

Any length.

tsx
<OtpField label="PIN" length={4} onComplete={unlock} />

Wrong code

`error` marks the group invalid and says what to do.

tsx
<OtpField label="Verification code" value={code} onValueChange={setCode} error={wrong ? "That code has expired. Ask for a new one." : undefined} />

Accessibility

  • One labelled group, not six unlabelled boxes: the visible label names the whole row, and each window says which digit it is.
  • autocomplete="one-time-code" is on by construction, so a phone offers the code from an SMS and password managers fill it (WCAG 3.3.8).
  • Pasting the whole code fills the row — nobody has to retype it digit by digit.
  • description and error are linked to the group with aria-describedby; error marks it invalid. The error is words plus a square pip, never colour alone.
  • Keyboard: typing a digit moves to the next window; Backspace and the arrow keys walk the row, and a pasted code fills it.

Tested against WCAG 2.2 AA on every release:

  • axe — No axe violations, in the component's own gallery and on its page.
  • keyboard — Every action is reachable and operable from the keyboard alone.
  • focus-visible — Focus is visible on every focusable part, in normal and forced-colors mode.
  • forced-colors — State stays visible when the look's colours are replaced by the system's.
  • target-size — Every target's real hit area is at least 24×24px, at every density.
  • reflow — Content reflows into 320px and survives a doubled text size.

Not covered: screen-reader: not yet verified by a person. Everything above is a machine check; a person has not yet driven this component with a screen reader.

Motion & sound

Motion tokens
--echo-duration-swap
Reduced motion
The windows don't sink, take strikes or ripple; only the focus edge fades.

Props

OTP field props
PropTypeDefault
idThe element's id, so a <label for> or an aria-describedby can reach it.string
nameIdentifies the code when a form is submitted.string
disabledboolean
requiredboolean
readOnlyboolean
autoFocusFocus this control when it mounts. One per page, at most.boolean
onBlurFired on focus loss. react-hook-form validates onTouched and onBlur with it.function
onFocusFired when the control takes focus.function
onKeyDownKeyboard handling you own — Enter to send, Escape to clear. Runs before Echo's.function
placeholderThe greyed hint shown while the field is empty. Never a substitute for a label.string
autoCompleteWhat the value is, for autofill and assistive tech — "email", "one-time-code". WCAG 1.3.5.string
inputModeWhich on-screen keyboard a phone offers: "numeric", "email", "tel", …string
maxLengthnumber
minLengthnumber
patternA regular expression the value must match for the field to be valid.string
labelVisible eyebrow label; also the group's accessible name. An OTP field needs label, aria-label or aria-labelledby: leaving all three out is a type error.string
lengthHow many digit windows.number6
valueControlled value — the whole code, not one digit.string
defaultValueUncontrolled initial code.string
onValueChangeFired with the code so far.function
onCompleteFired when the last window is filled. Where a sign-in screen submits.function
maskHide the characters. For a secret, not for a one-time code.booleanfalse
descriptionHelp text under the row, linked to the group.unknown
errorWhat's wrong, in words. While set, the group is invalid and the message shows with a square pip.string
aria-labelUsed only when label is omitted; a visible label wins.string
aria-labelledbyUsed only when label is omitted.string
sizeHeight on the control scale: sm 32px, md 44px, lg 60px, the same as a HardwareButton or Field of that size, so they line up in a row. Defaults to the nearest SizeProvider's size."sm" | "md" | "lg""md"

Anti-patterns

  • Don't use it for a password or anything long: it's for a short code, one character per window.
  • Don't block pasting — it is how most people enter a code they were just sent.

Changelog

  • v0.3.0 · 2026-10-12 · AddedThe drawn device (echo-ui-core, echo-ui-cli, every component that draws its own material). A seed's new render setting is molded (Echo as it has always been: plastic lit by one key light) or drawn: the same parts drawn in the ink, the way a spec sheet draws a key. Every part is outlined at one weight (--echo-line, --echo-line-width), hollow on the body; a raised part stands on a hard ink edge as deep as it rises and travels down it when pressed; a recess is an outline drawn inside; something floating stands on a deeper edge. There's no light, so no gloss, no soft shadow and no glow: what a molded device lights (an LED, the rail, a readout, the focus ring, a fader's knob, a radio's pip) is solid ink, and a low-emphasis action is its label underlined. In black and white (the accent the ink) "on" is solid ink and what's drawn on it inverts: a switch's thumb turns paper, a fader's knob is knocked out with a paper ring. The primary key is the paper key that stands highest, on an ink edge twice as deep as a neutral one's, the way a spec sheet draws its CTA. The accent stays the seed's own colour as a flat fill for what's on (a chosen segment, a checked box, a slider's travel, a switch that's on), so an acid highlighter is acid, not the olive a molded device holds it to; what's drawn on it is the ink, or the body when the accent is too deep for the ink. Pressing, travel, sound, what each material is for and every contrast guarantee are unchanged. npx echo-ui-cli style set render drawn turns it on; a style sets it in its seed; the published style and config schemas describe it, and DESIGN.md says how a drawn device builds. A molded device renders exactly as before: every line is 0px wide there, and each drawn value a component reads (--echo-drawn-fill, -on-fill, -ink, -rule, -glass, -hollow, -decoration) is initial, so it falls back to what the component always drew. HardwareButton's bed is the one new hand-tuned shadow: a drawn key stands on its own edge instead of being drawn in a recess.
  • v0.3.0 · 2026-10-12 · ChangedEvery item needs echo-ui-core 0.3.0 (all components). The drawn device, readability past AA and the design tests live in core, and the components that use them are built against it, so each item now declares echo-ui-core >=0.3.0 <0.4.0. Update core with the items: npm install echo-ui-core@^0.3.0 (or your package manager's), then npx echo-ui-cli update. An item whose files didn't change is the same code under a new version; the 0.2.0 files stay published.
  • v0.2.0 · 2026-10-04 · AddedThe light device (echo-ui-core, echo-ui-cli). Echo can be light: a pale chassis makes a device molded in light plastic, like a white calculator or a cream radio, and a dark one makes the device Echo has always been. There's no setting and no mode to switch; the chassis decides (devicePolarity, and values.polarity on the theme). On a light device the page is light: its ground, the well, is the body barely set in. Caps get their own ladder, a step lighter than the body with a lit rim that stops short of white, so they keep their bevel; undersides and seams are shaded darker; dim text moves toward the ground by the same step as on a dark device, and reads about 6:1 on it. Screens are paper glass printed in ink, because a glow on a pale body is a smudge. What's lit (an LED, the current rail) is still the accent, held to 3:1 on every ground, so on is brighter than off; the text it prints (a readout, a count, a current tab) and the focus ring are the accent's ink, a step deeper and held to AA, in the new accent-ink role. The primary cap is the same cap as a dark device's, the accent with a light label: its label is the new primary-cap-ink role, and progress cells, loader dots and a meter's fill, the same plastic, read 3:1 on the page. A neutral cap or a slider that fills with it under its own dark label fills with the new pour-* roles, the accent's pale stops. Shadows are drawn at half their weight, in a deep colour of the body's own hue (--echo-cast-ink) instead of black. Every guarantee holds as it does on a dark device, and the contrast sweep now runs on light bodies too. A dark seed makes exactly the theme it did before, and the new roles equal the ones they stand for there. The components that mixed a recess toward black, painted paper in the text colour or lit a pillow of light with it read the theme's new --echo-shade-ink, --echo-paper-stock and --echo-paper-ink instead, with the old value as the fallback, and a reflective screen reads --echo-screen-*; the components that print a lit label read --echo-primary-cap-ink and --echo-accent-ink the same way; every rail is drawn in the glow, and every focus ring, the ring recipes included, in the ink. style use wears a light style now, and style check says which device a style makes. A dark screen tint on a light body is still refused: one text colour can't serve both, and the theme says so.
  • v0.2.0 · 2026-10-04 · AddedOne size on everything with a height. Field, Select, NumberField, OtpField and Segmented take size="sm" | "md" | "lg" (32, 44 or 60px), matching HardwareButton, and all of them read a SizeProvider around them. md is exactly what they were. Avatar gains xs (inline with a line of text) and xl (a profile header).
  • v0.2.0 · 2026-10-04 · Addedecho-otp-field — the one-time code a sign-in asks for, as a row of lit digit windows. A pasted code fills the row, arrow keys and Backspace walk it, and autocomplete="one-time-code" lets a phone offer the code it just received.
  • v0.2.0 · 2026-10-04 · ChangedComponents whose shadow is a recipe read it by name. 71 shadows in 54 items now say var(--echo-shadow-<name>, <the same shadow>), so they look exactly as they did (every docs page was compared before and after) and follow a theme's recipes. Scope declares the recipes that read the accent again, so a Scope's own colour still reaches its focus rings and glows, and reflective screens do the same for theirs. Shadows that move with their part (a cap's drop as it's pressed) stay in the component.
  • v0.2.0 · 2026-10-04 · ChangedComments only, no behaviour change. Comments in the component source used to cite documents, milestones and ticket numbers from Echo's own planning, none of which exist in your project. The citations are gone and the sentences around them stay. Where a comment was only a citation, it now says what it meant. Three development warnings (HardwareButton's engraved/caption checks and StatusDot's missing-label check) also dropped the ticket code at the end of the message. echo-ui diff will show changes in most items; none of them are to code.
  • v0.2.0 · 2026-10-04 · ChangedAn item's version is now a function of declared data, not of how the changelog is formatted. The version an item ships under is published once and never rewritten, and it used to be inferred from prose: a regex for a bolded "Breaking" run across the whole unreleased section, and attribution by "does a bullet mention this name in backticks". One breaking entry therefore moved every item that changed that cycle, and an entry explaining that "Menu and Sheet are unchanged here" filed itself as a change to Menu and Sheet — which it really had.
  • v0.2.0 · 2026-10-04 · ChangedBreaking: every control takes a ref, an onBlur and an onFocus — and the two that were wide open are now closed. Four of 49 components could receive a ref, and onBlur appeared in zero public prop types, so react-hook-form's uncontrolled register() — which needs exactly ref, onBlur and name — could not work with any Echo control.
  • v0.2.0 · 2026-10-04 · ChangedThe agent brief says Echo has not shipped. llms.txt and the MCP server's instructions led with npx echo-ui-cli init, and that name on npm is a reserved stub with no executable — so a model following the brief wrote an install step that fails with npx's own error. The brief now opens with the caveat, and the docs carry it on every surface that shows a command. One switch (CLI_RELEASED) silences all of them at launch, and a test refuses to let one move without the others. Affects all components only in what the brief says about installing them; no item's props, CSS or rendered semantics change.
  • v0.2.0 · 2026-10-04 · ChangedEcho's home is echo-ui.com. The registry, the docs and the packages all move to it from echo.nawwara.studio. Nothing was published under the old host, so no echo.json anywhere points at it and there is nothing to migrate — this is the last release where that is true.
  • v0.2.0 · 2026-10-04 · ChangedWeights, line heights, letter-spacing, z-index, border widths and icon sizes come from the theme scales in all components, with the old value as a fallback, so components keep working with echo-ui-core@0.0.1. Strays moved to the nearest step: most by under a pixel; HardwareButton icons are 14/16/20px (were 15/17/19).
  • v0.2.0 · 2026-10-04 · FixedA light device's recesses keep the body's hue in Chromium (echo-ui-core, BUG-166). Chromium drops the hue of a colour under 0.02 chroma when it mixes in oklch, and draws the mix at hue 0, a rose. A light device's plastic is that grey, so on a lilac body every field, track and rail was pink. A mix made only of greys is made in oklab now, which has no hue to lose; a mix with an accent in it stays in oklch. On a dark device nothing you can see changes.
  • v0.2.0 · 2026-10-04 · FixedContent now reflows into a 320px screen (400% zoom) and survives a doubled browser text size (WCAG 1.4.10, 1.4.4), across all components. Select's 180px floor, NumberField's readout, Segmented and Steps as flex items, EmptyState's grid columns, and Avatar's fixed-pixel disc all gave way; Panel counts its padding inside a width you set (box-sizing: border-box), so a <Panel style={{ width: 220 }}> is now 220px wide overall rather than 260px.