# Verification code

A six-digit code input with paste and validation.

Access: pro. Category: Forms. Kind: composite.

## When to use

- Use it when a page needs a six-digit code input with paste and validation.
- Choose it when the host application can supply the required state and keep business logic outside the presentation component.

## Alternatives

- Choose form-field instead when a labeled email field with validation and help text is the actual interface need, rather than verification code.

## Setup for agents

Use React 19 and TypeScript. Initialize shadcn for your framework, then merge this exact entry into components.json:

```json
{
  "registries": {
    "@tidal-pro": {
      "url": "https://tidalui.com/r/pro/{name}.json",
      "headers": {
        "Authorization": "Bearer ${TIDALUI_TOKEN}"
      }
    }
  }
}
```

The namespace must be named **@tidal-pro** because transitive Pro dependencies use that namespace. Obtain an agent key from your active Pro account at https://tidalui.com/account. Keep TIDALUI_TOKEN in your local environment, never in components.json, client code, Git or logs.

```sh
export TIDALUI_TOKEN='your-private-agent-key'
npx shadcn@latest add @tidal-pro/waitlist-form
npx shadcn@latest add https://tidalui.com/r/tidal-button.json
```

Free command: `npx shadcn@latest add https://tidalui.com/r/<name>.json`.
Pro command: `npx shadcn@latest add @tidal-pro/<name>`.

Import the base stylesheet and every stylesheet listed on the installed item's metadata. For example:

```tsx
import "./components/ui/tidal.css";
import "./components/ui/hero-section.css";
// Place installed components inside this wrapper:
<div className="tidal-scope" data-theme="dark">...</div>
```

Omit data-theme for the default light theme. Put the attribute on the same tidal-scope element for dark mode. Every component installs the shared free tidal-base dependency. After upgrading, run `npx shadcn@latest add https://tidalui.com/r/tidal-base.json --overwrite` to receive current tokens. Review local modifications before overwriting.

Vite: Use React + TypeScript. Map @/* to ./src/* in paths and Vite resolve.alias. Import tidal.css and each component stylesheet in your application entry.

Next.js 15 App Router: Next.js App Router: import tidal.css and component CSS in app/layout.tsx. Interactive examples belong in a client component with "use client". Map @/* to ./* or ./src/* to match your project.

TypeScript 6: use paths without baseUrl:

```json
{
  "compilerOptions": {
    "paths": {
      "@/*": [
        "./src/*"
      ]
    }
  }
}
```

Pro registry requests are server/CLI-only. Use the same-origin account interface in a browser; cross-origin Authorization preflights are intentionally unsupported.


## Install Verification code

```sh
npx shadcn@latest add @tidal-pro/verification-code
```

Stylesheets: `components/ui/tidal.css`, `components/ui/verification-code.css`.

## Minimal example

```tsx
import"./components/ui/tidal.css";
import"./components/ui/verification-code.css";
import{TidalVerificationCode}from"./components/ui/verification-code";
export default()=><div className="tidal-scope"><TidalVerificationCode label={"Demo"} onValueChange={() => {}} value={"value"}/></div>;
```

## Structured props

- `TidalVerificationCode.label: string`: Required label value accepted by this exported component.
- `TidalVerificationCode.onValueChange: (value: string) => void`: Callback invoked when the value change interaction is proposed.
- `TidalVerificationCode.value: string`: Required value value accepted by this exported component.
- `TidalVerificationCode.description?: string | undefined`: Optional description value accepted by this exported component.
- `TidalVerificationCode.error?: string | undefined`: Optional error value accepted by this exported component.
- `TidalVerificationCode.formatCount?: ((filled: number, total: number) => string) | undefined` (default (filled, total) => `${filled} / ${total}`): Optional format count value accepted by this exported component.
- `TidalVerificationCode.length?: number | undefined` (default 6): Optional length value accepted by this exported component.
- `TidalVerificationCode.onComplete?: ((value: string) => void) | undefined`: Callback invoked when the complete interaction is proposed.
- `TidalVerificationCode.rootClassName?: string | undefined` (default ""): Optional root class name value accepted by this exported component.

## Complete usage example

[Source](https://tidalui.com/examples/verification-code.tsx) | [Manifest](https://tidalui.com/examples/verification-code.json). Install the listed additional dependencies. Consumer fixture: TypeScript pass; Vite pass. This fixture check is distinct from the actual shadcn install receipt.

```tsx
import "./components/ui/tidal.css";

import { useEffect, useLayoutEffect, useRef, useState } from "react";

import { ArrowUpRight, Check, Mail, RotateCcw } from "lucide-react";

import { TidalVerificationCode } from "./components/ui/verification-code";

import { TidalButton } from "./components/ui/tidal-button";

import "./components/ui/verification-code.css";



const tidalExampleStyles = ".verification-code-specimen {\n  width: 100%;\n  max-width: 620px;\n  padding: 28px;\n  border: 1px solid var(--t-border);\n  border-radius: var(--t-radius-card);\n  background: var(--t-surface);\n  box-shadow:\n    0 24px 40px -28px #00000030,\n    0 2px 4px #00000007;\n}\n.verification-code-specimen > h3 {\n  font-size: 29px;\n  line-height: 1.08;\n  letter-spacing: -1px;\n  font-weight: 500;\n  margin: 13px 0 26px;\n}\n.verification-code-specimen > h3 > em {\n  font-family: \"Instrument Serif\", serif;\n  font-size: 1.2em;\n  font-weight: 400;\n}\n.code-demo-stage {\n  overflow: hidden;\n  transition: height 420ms var(--t-ease-out);\n  padding: 7px 0;\n}\n.code-demo-content {\n  display: flow-root;\n}\n.code-demo-message {\n  display: flex;\n  align-items: center;\n  gap: 18px;\n  padding: 22px;\n  border: 1px solid var(--t-border);\n  border-radius: 12px;\n  background: var(--t-subtle);\n  position: relative;\n  overflow: hidden;\n  margin-bottom: 28px;\n}\n.code-demo-message:after {\n  content: \"\";\n  position: absolute;\n  top: 0;\n  right: 0;\n  width: 16px;\n  height: 16px;\n  background: linear-gradient(\n    225deg,\n    var(--t-surface) 50%,\n    var(--t-border) 50%,\n    var(--t-subtle)\n  );\n  pointer-events: none;\n}\n.code-demo-mail {\n  display: grid;\n  place-items: center;\n  width: 48px;\n  height: 48px;\n  border-radius: 12px;\n  background: var(--t-ink);\n  color: var(--t-surface);\n  transform: rotate(-5deg);\n  flex-shrink: 0;\n}\n.code-demo-message .demo-eyebrow {\n  font-size: 11px;\n  letter-spacing: 1px;\n}\n.code-demo-message strong {\n  display: block;\n  font-size: 26px;\n  letter-spacing: 4px;\n  font-weight: 400;\n  line-height: 1.1;\n  margin: 9px 0;\n  font-variant-numeric: tabular-nums;\n}\n.code-demo-message strong > span {\n  margin-left: 7px;\n}\n.code-demo-message p {\n  font-size: 11px;\n  color: var(--t-muted);\n  line-height: 1.6;\n  margin: 0;\n}\n.code-demo-stamp {\n  font-size: 11px;\n  letter-spacing: 1px;\n  color: var(--t-muted);\n  margin-left: auto;\n  align-self: flex-end;\n  white-space: nowrap;\n}\n.code-demo-checkpoint {\n  display: flex;\n  align-items: center;\n  gap: 12px;\n  margin-top: 21px;\n  font-size: 11px;\n  color: var(--t-muted);\n}\n.code-demo-track {\n  width: 52px;\n  height: 3px;\n  border-radius: 4px;\n  background: var(--t-border);\n  flex-shrink: 0;\n  overflow: hidden;\n}\n.code-demo-track > span {\n  height: 100%;\n  display: block;\n  border-radius: 4px;\n  background: var(--t-ink);\n  transition: width 420ms var(--t-ease-out);\n}\n.code-demo-actions {\n  display: flex;\n  gap: 10px;\n  margin-top: 22px;\n  align-items: center;\n}\n.tidal-scope .code-demo-actions > .tidal-button {\n  font-size: 11px;\n  flex: 1;\n  padding: 0 14px;\n  min-width: 0;\n}\n.tidal-scope .code-demo-reset {\n  display: grid;\n  place-items: center;\n  width: 44px;\n  height: 44px;\n  border: 1px solid var(--t-border);\n  border-radius: 10px;\n  background: var(--t-subtle);\n  color: var(--t-muted);\n  flex-shrink: 0;\n  transition:\n    background 180ms,\n    color 180ms,\n    transform 320ms var(--t-ease-out);\n}\n.code-demo-reset:hover:not(:disabled) {\n  background: var(--t-wash);\n  color: var(--t-ink);\n  transform: rotate(-12deg);\n}\n.code-demo-reset:disabled {\n  cursor: not-allowed;\n  opacity: 0.5;\n}\n.code-demo-note {\n  font-size: 11px;\n  line-height: 1.7;\n  color: var(--t-muted);\n  margin: 16px 0 0;\n}\n.code-demo-complete {\n  text-align: center;\n  padding: 27px 23px;\n  border: 1px solid var(--t-border);\n  border-radius: 12px;\n  background: var(--t-subtle);\n  animation: code-demo-complete-in 420ms var(--t-ease-out) both;\n}\n.code-demo-success-icon {\n  display: grid;\n  place-items: center;\n  width: 54px;\n  height: 54px;\n  border-radius: 50%;\n  background: var(--t-ink);\n  color: var(--t-surface);\n  margin: 0 auto 24px;\n  animation: code-demo-icon-in 420ms var(--t-ease-spring) both;\n}\n.code-demo-complete > .demo-eyebrow {\n  display: block;\n  font-size: 11px;\n}\n.code-demo-complete > h4 {\n  font-size: 25px;\n  line-height: 1.2;\n  letter-spacing: -0.8px;\n  font-weight: 500;\n  margin: 13px 0;\n}\n.code-demo-complete > p {\n  font-size: 11px;\n  color: var(--t-muted);\n  line-height: 1.8;\n  max-width: 330px;\n  margin: 0 auto 24px;\n}\n.code-demo-complete > .tidal-button {\n  font-size: 11px;\n}\n@media (max-width: 480px) {\n  .verification-code-specimen {\n    padding: 20px;\n  }\n  .code-demo-message {\n    padding: 19px 15px;\n    gap: 12px;\n  }\n  .code-demo-message strong {\n    font-size: 22px;\n    letter-spacing: 3px;\n  }\n  .code-demo-stamp {\n    display: none;\n  }\n  .code-demo-actions {\n    gap: 7px;\n  }\n  .tidal-scope .code-demo-actions > .tidal-button {\n    font-size: 11px;\n    padding: 0 10px;\n  }\n}\n@keyframes code-demo-complete-in {\n  from {\n    opacity: 0;\n    transform: translateY(8px);\n  }\n  to {\n    opacity: 1;\n    transform: none;\n  }\n}\n@keyframes code-demo-icon-in {\n  from {\n    opacity: 0;\n    transform: scale(0.7) rotate(-12deg);\n  }\n  to {\n    opacity: 1;\n    transform: none;\n  }\n}\n@media (prefers-reduced-motion: reduce) {\n  .code-demo-reset:hover:not(:disabled),\n  .code-demo-mail {\n    transform: none;\n  }\n}\n.tidal-scope .code-demo-actions .tidal-button:focus-visible,\n.tidal-scope .code-demo-reset:focus-visible {\n  outline: 2px solid currentColor;\n  outline-offset: -5px;\n}";

const sample = "548207";

export function VerificationCodeDemo() {
  const [code, setCode] = useState("");
  const [error, setError] = useState("");
  const [phase, setPhase] = useState<"editing" | "checking" | "complete">(
    "editing",
  );
  const [height, setHeight] = useState<number>();
  const input = useRef<HTMLInputElement>(null);
  const title = useRef<HTMLHeadingElement>(null);
  const content = useRef<HTMLDivElement>(null);
  const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
  const restore = useRef(false);
  const focusOwner = useRef<HTMLElement | null>(null);
  useEffect(() => () => clearTimeout(timer.current), []);
  useLayoutEffect(() => {
    const active = document.activeElement;
    const canMoveFocus =
      active === document.body || active === focusOwner.current;
    if (phase === "complete" && canMoveFocus) {
      title.current?.focus({ preventScroll: true });
      focusOwner.current = null;
    } else if (phase === "editing" && restore.current) {
      restore.current = false;
      if (canMoveFocus) {
        input.current?.focus({ preventScroll: true });
        input.current?.select();
      }
      focusOwner.current = null;
    }
  }, [phase]);
  useLayoutEffect(() => {
    const node = content.current;
    if (!node) return;
    const measure = () => {
      const css = getComputedStyle(node.parentElement!);
      setHeight(
        node.offsetHeight +
          Number.parseFloat(css.paddingTop) +
          Number.parseFloat(css.paddingBottom),
      );
    };
    measure();
    const ro = new ResizeObserver(measure);
    ro.observe(node);
    return () => ro.disconnect();
  }, []);
  function reset() {
    clearTimeout(timer.current);
    focusOwner.current =
      document.activeElement instanceof HTMLElement
        ? document.activeElement
        : null;
    setCode("");
    setError("");
    restore.current = true;
    setPhase("editing");
    if (phase === "editing") {
      restore.current = false;
      input.current?.focus({ preventScroll: true });
    }
  }
  return (
    <div className="verification-code-specimen">
      <div className="code-demo-stage" style={{ height }}>
        <div ref={content} className="code-demo-content">
          {phase === "complete" ? (
            <div className="code-demo-complete">
              <span className="code-demo-success-icon" aria-hidden="true">
                <Check size={26} />
              </span>
              <span className="demo-eyebrow">
                SIX DIGITS · ONE CLEAR NEXT STEP
              </span>
              <h4 ref={title} tabIndex={-1}>
                The sample matched.
              </h4>
              <p>
                This was a local demonstration. No account was accessed and no
                email was sent.
              </p>
              <TidalButton variant="secondary" onClick={reset}>
                Try another sample
              </TidalButton>
            </div>
          ) : (
            <>
              <div className="code-demo-message">
                <span className="code-demo-mail" aria-hidden="true">
                  <Mail size={21} />
                </span>
                <div>
                  <span className="demo-eyebrow">ORIGINAL SAMPLE CODE</span>
                  <strong>
                    {sample.slice(0, 3)} <span>{sample.slice(3)}</span>
                  </strong>
                  <p>Use these digits to explore the flow.</p>
                </div>
                <span className="code-demo-stamp" aria-hidden="true">
                  N / 025
                </span>
              </div>
              <form
                noValidate
                onSubmit={(event) => {
                  event.preventDefault();
                  if (code.length !== 6) {
                    setError("Enter all six digits to check the sample.");
                    input.current?.focus({ preventScroll: true });
                    return;
                  }
                  focusOwner.current =
                    (event.nativeEvent as SubmitEvent).submitter instanceof
                    HTMLElement
                      ? (event.nativeEvent as SubmitEvent).submitter
                      : document.activeElement instanceof HTMLElement
                        ? document.activeElement
                        : null;
                  setError("");
                  setPhase("checking");
                  timer.current = setTimeout(() => {
                    if (code === sample) {
                      setCode("");
                      setPhase("complete");
                    } else {
                      setError(
                        "Those digits do not match the sample. Try the displayed code.",
                      );
                      restore.current = true;
                      setPhase("editing");
                    }
                  }, 700);
                }}
              >
                <TidalVerificationCode
                  ref={input}
                  label="Sample verification code"
                  name="sample-code"
                  value={code}
                  onValueChange={(next) => {
                    setCode(next);
                    setError("");
                  }}
                  error={error}
                  disabled={phase === "checking"}
                  description="Type the digits, or paste a complete sample code."
                  required
                />
                <div className="code-demo-checkpoint">
                  <span className="code-demo-track">
                    <span style={{ width: `${(code.length / 6) * 100}%` }} />
                  </span>
                  <span role={phase === "checking" ? "status" : undefined}>
                    {phase === "checking"
                      ? "Checking the sample…"
                      : error
                        ? "Review the sample digits"
                        : code.length === 6
                          ? "Ready for the sample check"
                          : `${code.length} of 6 digits entered`}
                  </span>
                </div>
                <div className="code-demo-actions">
                  <TidalButton
                    type="button"
                    variant="secondary"
                    onClick={() => {
                      if (phase === "checking") {
                        reset();
                        return;
                      }
                      setCode(sample);
                      setError("");
                      input.current?.focus({ preventScroll: true });
                      input.current?.setSelectionRange(0, 6);
                    }}
                  >
                    {phase === "checking" ? "Cancel check" : "Fill sample"}
                  </TidalButton>
                  <TidalButton type="submit" loading={phase === "checking"}>
                    Check sample
                    <ArrowUpRight size={13} aria-hidden="true" />
                  </TidalButton>
                  <button
                    type="button"
                    className="code-demo-reset"
                    aria-label="Clear sample code"
                    onClick={reset}
                    disabled={phase === "checking"}
                  >
                    <RotateCcw size={15} />
                  </button>
                </div>
              </form>
            </>
          )}
        </div>
      </div>
      <p className="code-demo-note">
        A local sample, with no delivery, authentication or account access.
      </p>
    </div>
  );
}

export default function AgentExample() {
  return (
    <div className="tidal-scope" data-theme="light" dir="ltr">
      <style>{tidalExampleStyles}</style>
      <VerificationCodeDemo />
    </div>
  );
}

```

## Gotchas

- Keep field state, validation results, submission, and persistence in the host form workflow.

## Theme and accessibility

{"tokens":["--t-accent","--t-border","--t-border-strong","--t-canvas","--t-danger","--t-display","--t-ease-out","--t-ease-spring","--t-faint","--t-font","--t-ink","--t-line","--t-muted","--t-primary","--t-primary-contrast","--t-radius-card","--t-radius-control","--t-radius-overlay","--t-radius-panel","--t-ring","--t-shadow-lg","--t-shadow-soft","--t-soft","--t-subtle","--t-surface","--t-wash"],"darkMode":true}

{"keyboard":["Tab and Shift+Tab follow the component's native focus order.","Arrow-key behavior follows the exported composite-control implementation."],"aria":"The component wires labels and relationships from consumer-provided visible text or ARIA props; preserve those labels in production.","notes":"Verify focus visibility, text alternatives, contrast, and reduced motion in the final composition."}

Required visible label, controlled value:string and onValueChange(string). Optional onComplete(code) fires after user edits produce a changed complete code; it does not fire on initial or external values and introduces no automatic submission. length(default6) floors/clamps1..8; nonfinite falls back6. ASCII digits only; render and edits remove other characters and truncate to length without mutating caller state on render. Native text input/ref/name/required/disabled/readOnly/id, keyboard, focus, blur, selection and composition attributes supported; pointer selection belongs to the slot row; className applies to input, rootClassName to wrapper. Numeric inputMode, exact-length minLength/pattern and one-time-code autocomplete(default) are provided; maxLength is omitted so formatted paste can be normalized. One accessible input owns Tab, arrows, Home/End, Shift selection, Backspace/Delete, clipboard and autofill; decorative slots are aria-hidden. Pointer selection focuses/selects a digit; shared frame follows native selection. Composition drafts retain native input text until commit; caller composition/select/focus/blur handlers compose. Optional description/error link with external aria-describedby; error sets aria-invalid and role=alert. formatCount localizes the visible count, linked to the input without live per-keystroke announcements. No verification, delivery, account access or code storage is introduced. Consumers own validation/authentication/network handling. Native autofill attributes are present; native IME and actual SMS/device autofill are not browser-tested. Reduced motion resolves frames and digits instantly.
