Code

<!-- pearl-code.free.js: download it from the Install section below and host it with your site -->
<script src="/pearl-code.free.js" defer></script>

<pearl-code
  length="6"
  group="3"
  size="54"
  theme="light"
  label="Verification code"
></pearl-code>

<script>
  const code = document.querySelector('pearl-code');
  code.addEventListener('complete', async (e) => {
    const ok = await verify(e.detail.value);   // your check
    code.setAttribute('status', ok ? 'success' : 'error');
  });
</script>

In context

Check your phone
We sent a code to •• 42. Try 246810.
Two-step sign-in
PIN and invite code, Mint and Sunset Pro

Install · Free Web Component

One file, no dependencies. Aurora preset, every other option included. Host it yourself so your visitors never load anything from our servers.

1. Install with one command — or download the file
shadcn CLI · React
npx shadcn@latest add https://www.ui-design.co/r/pearl-code.json
2. Load it and use the element
HTML
<!-- pearl-code.free.js: download it from the Install section below and host it with your site -->
<script src="/pearl-code.free.js" defer></script>

<pearl-code
  length="6"
  group="3"
  size="52"
  theme="light"
  label="Verification code"
></pearl-code>

<script>
  const code = document.querySelector('pearl-code');
  code.addEventListener('complete', async (e) => {
    const ok = await verify(e.detail.value);   // your check
    code.setAttribute('status', ok ? 'success' : 'error');
  });
</script>
3. React + TypeScript (optional)

The shadcn command adds a typed React wrapper for you. Using the file directly? Custom elements work in React as-is; for type checking add:

TypeScript
// pearl-code.d.ts
declare namespace JSX {
  interface IntrinsicElements {
    'pearl-code': React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement> & {
      length?: number | string;
      value?: string;
      type?: 'numeric' | 'text';
      mask?: boolean | '';
      group?: number | string;
      status?: 'idle' | 'error' | 'success';
      size?: number | string;
      theme?: 'light' | 'dark';
      name?: string;
      label?: string;
      disabled?: boolean | '';
      sound?: boolean | '';
    };
  }
}

Pro · React + TypeScript Pro

One payment of $4.99, yours forever. Use it in unlimited personal and commercial projects; no resale.

  • React component (controlled or uncontrolled) with TypeScript types, onChange and onComplete, and the full source
  • Sunset, Mint and Mono tints, plus custom tints from Brand Fit
  • The vanilla Web Component with every tint, a demo page, README and license

Attributes & props

NameTypeDefaultDescription
length number6Number of cells (1–12).
value string''The code so far. Fires change as it is typed and complete when every cell is filled.
type 'numeric' | 'text''numeric'Digits only, or letters and digits (upper-cased) for invite and promo codes.
mask booleanoffShows dots instead of the characters, for a PIN.
group number0Puts a separator after every N cells: 3 gives 123 – 456.
status 'idle' | 'error' | 'success''idle'Set it after you check the code: error shakes the row and turns the glow coral, success turns it green.
size number (px)52Cell width; the height, gaps and type scale with it.
theme 'light' | 'dark''light'White porcelain or dark wells.
name string—Form field name: the code is submitted with the surrounding form.
label string'Verification code'Accessible name of the field. aria-label in React.
autofocus / disabled booleanoffFocus it on load; dim it and ignore input.
sound booleanoffA porcelain tap per character, rising along the row, and a chime when complete (plus a tap of vibration on phones). Also on for everything inside an element with data-ui-sound="on".
tint Pro'aurora' | 'sunset' | 'mint' | 'mono' | object'aurora'Glow colours, or a custom tint. Free build ships Aurora only.

There is one real input under the cells, so pasting a code, the SMS suggestion on iOS and Android (autocomplete="one-time-code"), password managers and screen readers behave as they do on a plain field. Backspace removes the last character. Clear it by setting value to an empty string (or clear() on the element) after an error. Everything is CSS — no WebGL, no canvas — and reduced motion keeps the tiles and glow but drops the hop, the wave and the shake.

More components