Back to the library

Caret — inline suggestion, Tab to accept

Variant: Ghost accept

Inline completion: grey text after the caret that Tab makes the user’s own. The suggestion waits about 420ms after the last keystroke, because one that appears mid-word interrupts the typing, then fades in over 120ms and never moves — it is not the user’s text yet, so it gets no entrance travel and no colour, only a place to sit. The Tab hint arrives and leaves with it. Accepting is one keystroke, so all fourteen characters start darkening together and reach the reading colour in 120ms, with no left-to-right wipe pretending they were typed, and the caret jumps to the end of the line on the same frame. Text nobody typed needs checking, so the accepted range keeps a clay wash that fades over about 800ms and shows exactly what arrived. The caret steps with the typing and jumps with the accept; it never glides after an edit, because a caret that slides after the text changes shows the same edit twice. Reach for it for AI completions, command-bar autocomplete, and anywhere a machine offers to finish the user’s sentence.

textkeyboardllmconfirmationemphasisloop

The source

A complete HTML document. Paste it into an empty .html file and it plays — no stylesheet, script, font, or image to fetch.

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Caret — inline suggestion, Tab to accept</title>
    <style>
      :root {
        /* Neutrals — fixed, never remixed. */
        --ivory: #faf9f5;
        --paper: #ffffff;
        --oat: #e3dacc;
        --slate: #141413;

        /* Knobs — the remix API. A knob exists iff declared here and used below. */
        --hue: 38.8;
        --lift: 0;
        --chroma: 1;
        --round: 1;
        --speed: 1;

        /* Accents — derived from the knobs with the family's offsets baked in,
           so one hue roll moves them together. Defaults reproduce the original hex. */
        --clay: oklch(calc(0.6724 + var(--lift)) calc(0.1308 * var(--chroma)) var(--hue));
        --clay-d: oklch(calc(0.5797 + var(--lift)) calc(0.127 * var(--chroma)) var(--hue));
        --olive: oklch(
          calc(0.6118 + var(--lift)) calc(0.0713 * var(--chroma)) calc(var(--hue) + 88.3)
        );
        --rust: oklch(
          calc(0.5408 + var(--lift)) calc(0.1357 * var(--chroma)) calc(var(--hue) - 10.3)
        );

        /* Clock — 5.6s. Seven keys land 60ms apart from 10% (the last at
           16.43%); the suggestion waits ~420ms after it (24%) and fades in over
           120ms; Tab lands at 50%; the loop rewinds inside a dark window at
           91–98%. */
        --cycle: 5.6s;
        --t: calc(var(--cycle) / var(--speed));

        --ease-out: cubic-bezier(0.23, 1, 0.32, 1);

        --_read: color-mix(in srgb, var(--slate) 80%, transparent);
        --_quiet: color-mix(in srgb, var(--slate) 52%, transparent);
        --_ghost: color-mix(in srgb, var(--slate) 34%, transparent);
        --_wash: color-mix(in srgb, var(--clay) 22%, transparent);
      }

      * {
        box-sizing: border-box;
        margin: 0;
        padding: 0;
      }

      body {
        min-height: 100vh;
        display: grid;
        place-items: center;
        padding: clamp(12px, 3vw, 28px);
        background: var(--ivory);
        color: var(--slate);
        font-family:
          system-ui,
          -apple-system,
          'Segoe UI',
          Roboto,
          sans-serif;
      }

      .card {
        width: min(360px, 92vw);
        padding: clamp(15px, 3.6vw, 24px) clamp(16px, 3.8vw, 26px);
        border: 1px solid var(--oat);
        border-radius: calc(14px * var(--round));
        background: var(--paper);
      }

      .eyebrow {
        font-size: clamp(11px, 2.4vw, 12.5px);
        font-weight: 600;
        letter-spacing: 0.09em;
        text-transform: uppercase;
        color: var(--_quiet);
      }

      .stage {
        animation: seam var(--t) infinite;
      }

      .code {
        position: relative;
        margin-top: clamp(10px, 2vw, 15px);
        white-space: pre;
        font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
        font-size: clamp(14px, 4.4vw, 19px);
        line-height: 1.7;
        color: var(--_read);
        isolation: isolate;
      }

      .code .k {
        color: var(--clay-d);
      }

      .typed,
      .ghost {
        display: inline-block;
      }

      /* The word types itself from its left edge, one character a step. */
      .typed {
        animation: type var(--t) infinite;
      }

      /* The suggestion is grey and never moves. It is not the user's text
         yet, so it gets no entrance travel, no colour and no claim on the
         caret — it sits after it, in the place it would go. */
      .ghost {
        color: var(--_ghost);
        animation: ghost var(--t) infinite;
      }

      /* What was just accepted stays marked for 800ms. Accepting is one
         keystroke that writes fourteen characters the user did not type, and
         the wash is the receipt: it says exactly which ones. */
      .wash {
        position: absolute;
        top: calc(1.7em + 0.16em);
        left: 9ch;
        width: 14ch;
        height: 1.38em;
        border-radius: calc(3px * var(--round));
        background: var(--_wash);
        opacity: 0;
        z-index: -1;
        animation: wash var(--t) infinite;
      }

      .caret {
        position: absolute;
        top: 0.22em;
        left: 0;
        width: max(2px, 0.09em);
        height: 1.26em;
        margin-left: -1px;
        border-radius: 999px;
        background: var(--clay);
        animation:
          caret var(--t) infinite,
          blink var(--t) infinite;
      }

      .hint {
        display: flex;
        align-items: center;
        gap: 8px;
        height: 1.9em;
        margin-top: clamp(12px, 2.6vw, 18px);
        font-size: clamp(11px, 2.5vw, 12.5px);
        color: var(--_quiet);
        opacity: 0;
        animation: hint var(--t) infinite;
      }

      .hint b {
        display: inline-block;
        padding: 0.12em 0.6em;
        border: 1px solid var(--oat);
        border-bottom-width: 2px;
        border-radius: calc(5px * var(--round));
        background: var(--ivory);
        font-weight: 500;
        color: var(--slate);
        animation: press var(--t) infinite;
      }

      @keyframes type {
        0%,
        10% {
          clip-path: inset(0 100% 0 0);
          animation-timing-function: steps(7, jump-start);
        }
        17.5%,
        94.9% {
          clip-path: inset(0 0 0 0);
        }
        95%,
        100% {
          clip-path: inset(0 100% 0 0);
        }
      }

      /* In on ease-out once typing has paused, because a suggestion that
         arrives mid-word is an interruption. On Tab it inks to the reading
         colour in 120ms — no wipe, since accepting is one command and all
         fourteen characters became the user's on the same frame. */
      @keyframes ghost {
        0%,
        24% {
          opacity: 0;
          color: var(--_ghost);
          animation-timing-function: var(--ease-out);
        }
        26.14%,
        50% {
          opacity: 1;
          color: var(--_ghost);
          animation-timing-function: ease;
        }
        52.14%,
        94.9% {
          opacity: 1;
          color: var(--_read);
        }
        95%,
        100% {
          opacity: 0;
          color: var(--_ghost);
        }
      }

      @keyframes wash {
        0%,
        49.99% {
          opacity: 0;
        }
        50%,
        52% {
          opacity: 1;
          animation-timing-function: ease;
        }
        66%,
        100% {
          opacity: 0;
        }
      }

      /* The caret is pushed by text, never glides with it: it steps a
         character at a time with the typing, holds still beside the
         suggestion, and jumps the fourteen accepted characters on the Tab
         frame. A caret that slid after an edit would announce it twice. */
      @keyframes caret {
        0%,
        10% {
          transform: translate(2ch, 1.7em);
          animation-timing-function: steps(7, jump-start);
        }
        17.5%,
        49.99% {
          transform: translate(9ch, 1.7em);
        }
        50%,
        94.9% {
          transform: translate(23ch, 1.7em);
        }
        95%,
        100% {
          transform: translate(2ch, 1.7em);
        }
      }

      /* Solid while typing and for 500ms after the last key, then the
         ordinary 500ms rhythm; the Tab restarts the phase. */
      @keyframes blink {
        0%,
        1.07% {
          opacity: 1;
        }
        1.08%,
        9.99% {
          opacity: 0;
        }
        10%,
        25.36% {
          opacity: 1;
        }
        25.37%,
        34.29% {
          opacity: 0;
        }
        34.3%,
        43.22% {
          opacity: 1;
        }
        43.23%,
        49.99% {
          opacity: 0;
        }
        50%,
        58.93% {
          opacity: 1;
        }
        58.94%,
        67.86% {
          opacity: 0;
        }
        67.87%,
        76.79% {
          opacity: 1;
        }
        76.8%,
        85.72% {
          opacity: 0;
        }
        85.73%,
        100% {
          opacity: 1;
        }
      }

      /* The affordance arrives with the suggestion and leaves with it. */
      @keyframes hint {
        0%,
        24% {
          opacity: 0;
          animation-timing-function: var(--ease-out);
        }
        26.14%,
        50% {
          opacity: 1;
          animation-timing-function: ease;
        }
        53%,
        100% {
          opacity: 0;
        }
      }

      @keyframes press {
        0%,
        48.6% {
          transform: translateY(0);
        }
        49%,
        50.4% {
          transform: translateY(1px);
        }
        51%,
        100% {
          transform: translateY(0);
        }
      }

      @keyframes seam {
        0%,
        91% {
          opacity: 1;
          animation-timing-function: ease;
        }
        93.5%,
        96% {
          opacity: 0;
          animation-timing-function: ease;
        }
        98.5%,
        100% {
          opacity: 1;
        }
      }

      @media (prefers-reduced-motion: reduce) {
        /* Nothing here travels except the key dip and the stepped typing.
           The word arrives as one fade, the key lights without dipping, and
           the suggestion still waits, still inks, still leaves its receipt —
           on a clock 1.6x slower. */
        .stage,
        .typed,
        .ghost,
        .wash,
        .caret,
        .hint {
          animation-duration: calc(var(--t) * 1.6);
        }

        .hint b {
          animation: none;
        }

        .caret {
          animation-name: caret-rm, blink;
        }

        @keyframes caret-rm {
          0%,
          9.99% {
            transform: translate(2ch, 1.7em);
          }
          10%,
          49.99% {
            transform: translate(9ch, 1.7em);
          }
          50%,
          94.9% {
            transform: translate(23ch, 1.7em);
          }
          95%,
          100% {
            transform: translate(2ch, 1.7em);
          }
        }

        .typed {
          clip-path: none;
          animation-name: type-rm;
        }

        @keyframes type-rm {
          0%,
          10% {
            opacity: 0;
            animation-timing-function: ease;
          }
          14%,
          94.9% {
            opacity: 1;
          }
          95%,
          100% {
            opacity: 0;
          }
        }
      }
    </style>
  </head>
  <body>
    <div class="card">
      <p class="eyebrow">retry.ts</p>
      <div class="stage">
        <div
          class="code"
          role="img"
          aria-label="Return is typed, a grey inline suggestion appears after the caret, and pressing Tab accepts it: the suggestion turns into ordinary text, briefly highlighted, and the caret jumps to the end of the line."
        ><span class="wash"></span><div><span class="k">function</span> backoff(n) {</div><div>  <span class="typed"><span class="k">return</span> </span><span class="ghost">base * 2 ** n;</span></div><div>}</div><span class="caret"></span></div>
        <p class="hint" aria-hidden="true"><b>Tab</b><span>to accept</span></p>
      </div>
    </div>
  </body>
</html>

The variant family

Same idea, one axis moved. Compare them side by side before you commit.