Skip to content

One-time code input in HTML and CSS

Six boxes for the code received by email or text: automatic move to the next box, whole-code paste, arrow keys and backspace.

Here is an excerpt of this component's code in HTML and CSS. The full code is free for members, ready to copy into your project.

This component also comes in

Open in a new tab

The code in HTML and CSS

code-input.js
document.querySelectorAll("[data-ccv]").forEach((root) => {
  const form = root.querySelector("form");
  const field = form.elements.code;
  const boxes = [...root.querySelectorAll("[data-ccv-digit]")];
  const error = root.querySelector("[data-ccv-error]");
  const message = root.querySelector("[data-ccv-message]");
  const resend = root.querySelector("[data-ccv-resend]");
  const wait = root.querySelector("[data-ccv-wait]");
  const status = root.querySelector("[data-ccv-status]");
  const values = boxes.map(() => "");
  let timer = 0;
index.html
<!doctype html>
<html lang="fr">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Saisie de code à usage unique</title>
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
    <main class="demo">
      <section class="ccv" aria-labelledby="ccv-titre" data-ccv>
        <svg class="ccv__badge" viewBox="0 0 24 24" width="28" height="28" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><rect x="3" y="5" width="18" height="14" rx="2.5" /><path d="m4 7 8 6 8-6" /></svg>
style.css
:root {
  --ccv-bg: #ffffff;
  --ccv-text: #13232b;
  --ccv-muted: #475763;
  --ccv-line: #d5dde3;
  --ccv-field: #ffffff;
  --ccv-field-line: #9aa8b6;
  --ccv-filled: #f0fdfa;
  --ccv-accent: #0f766e;
  --ccv-accent-hover: #115e59;
  --ccv-accent-text: #ffffff;
  --ccv-ring: rgb(15 118 110 / 0.18);

Free component: copy it freely, including for commercial projects.

Forms and inputs components in HTML and CSS
  • A quote request form for tradespeople: the customer describes the work, picks a start date range and attaches up to six site photos, each with a preview, its size and a button to remove it.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A quote request form whose labels, hints and error messages are full French sentences, still readable at 320 px: nothing overflows, nothing is cut off, and each error is tied to its field.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • Visitors pick a package and tick options: the pre-tax total, VAT and total including tax update live, and the summary is sent with the contact form.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A short NPS survey: a 0 to 10 score as radio buttons, then a follow-up question adapted to whether the customer is a detractor, passive or promoter.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • An honest unsubscribe page: address prefilled from the link, choice between stopping everything or receiving less, optional reason and an undo.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A callback request form: French phone number checked and formatted, topic, working day and time slot, with explicit consent to the call.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component