Back to the library

Latch — snap dome

Variant: Snap dome

Why a good key clicks, drawn as the force curve it comes from. A key on a metal dome is pressed and released while a dot traces force against travel. The hand applies force, not position, so the press creeps on a mild ease-in as the dome softens toward its peak. Past the peak the dome stops resisting but the finger keeps pushing, and the key covers the second half of its travel in 45ms, accelerating into the board. The dot does not ride the falling curve. It runs straight across at the force the finger was already applying, and the shaded gap between that line and the curve is the surplus the finger feels as the click. Release mirrors it lower down: the dot slides back to the valley, then the dome pops the key up in 50ms at a smaller force. Two jumps at two forces are the hysteresis that stops a resting finger from chattering the switch. Reach for it when a press should confirm itself through the hand alone — a big target, a press-to-commit, anything used without looking.

physicscontrolgesturechartloop

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>Latch — snap dome</title>
    <style>
      /* One registered number: key travel, 0 to 10. The cap's depth and the
         dome's height are both functions of it; the dot on the force curve
         runs on the same keyframe stops and the same curves, so the key and
         its plot are one event drawn twice. */
      @property --_k {
        syntax: '<number>';
        inherits: true;
        initial-value: 0;
      }

      :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)
        );

        --_muted: color-mix(in srgb, var(--slate) 52%, transparent);
        --_faint: color-mix(in srgb, var(--slate) 22%, transparent);

        /* Clock — 3.6s: creep, snap, hold, ease off, pop, rest. */
        --cycle: 3.6s;
        --t: calc(var(--cycle) / var(--speed));
      }

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

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

      .rig {
        display: grid;
        gap: clamp(8px, 3vh, 14px);
        justify-items: center;
        animation: travel var(--t) infinite;
      }

      .cap,
      .foot {
        font-size: 11px;
        letter-spacing: 0.04em;
        color: var(--_muted);
      }

      .foot {
        white-space: nowrap;
        opacity: 0;
        animation: foot-in var(--t) linear infinite;
      }

      /* ---- the key, in section ---- */

      .key {
        position: relative;
        width: 96px;
        height: 66px;
      }

      .keycap {
        position: absolute;
        left: 22px;
        top: 22px;
        width: 52px;
        height: 22px;
        transform: translateY(calc(var(--_k) * 1.5px));
      }

      .keycap .face {
        position: absolute;
        inset: 0;
        border-radius: calc(5px * var(--round));
        background: var(--paper);
        border: 1.5px solid var(--oat);
        box-shadow: 0 1px 3px color-mix(in srgb, var(--slate) 14%, transparent);
      }

      .tip {
        position: absolute;
        left: 16px;
        top: -20px;
        width: 20px;
        height: 20px;
        border-radius: 50%;
        background: var(--clay-d);
        opacity: 0;
        transform: scale(0.6);
        animation: grip var(--t) infinite;
      }

      /* The dome's apex is always under the cap: its height is 16 minus the
         cap's travel, so the collapse is the same jump the cap makes. */
      .dome {
        position: absolute;
        left: 30px;
        top: 44px;
        width: 36px;
        height: 16px;
        transform-origin: bottom;
        transform: scaleY(calc((16 - var(--_k) * 1.5) / 16));
      }

      .dome svg {
        display: block;
        width: 100%;
        height: 100%;
        overflow: visible;
      }

      .dome path {
        fill: none;
        stroke: var(--_muted);
        stroke-width: 1.5;
        vector-effect: non-scaling-stroke;
      }

      .board {
        position: absolute;
        left: 14px;
        top: 60px;
        width: 68px;
        height: 4px;
        border-radius: calc(2px * var(--round));
        background: var(--oat);
      }

      /* ---- the force curve ---- */

      .plot {
        position: relative;
        width: 200px;
        height: 80px;
      }

      .plot svg {
        display: block;
        overflow: visible;
      }

      .axis {
        fill: none;
        stroke: var(--_faint);
        stroke-width: 1;
      }

      .curve {
        fill: none;
        stroke: var(--oat);
        stroke-width: 2;
        stroke-linejoin: round;
      }

      .jump {
        stroke: var(--_muted);
        stroke-width: 1;
        stroke-dasharray: 2 3;
      }

      /* The region between the hand's force and the dome's resistance while
         the key is in free fall. That surplus is what the finger feels. */
      .surplus {
        fill: var(--clay);
        opacity: 0;
        animation: surplus var(--t) infinite;
      }

      .axl {
        position: absolute;
        font-size: 11px;
        color: var(--_muted);
      }

      .axl.f {
        left: 14px;
        top: -4px;
      }

      .axl.x {
        right: 0;
        bottom: 0;
      }

      .dot {
        position: absolute;
        left: 0;
        top: 0;
        width: 8px;
        height: 8px;
        border-radius: 50%;
        background: var(--slate);
        offset-path: path(
          'M10,72 C30,46 62,22 82,22 L152,22 C146,40 136,54 122,54 L26.1,54 L10,72'
        );
        offset-rotate: 0deg;
        offset-anchor: center;
        offset-distance: 0%;
        animation: dot var(--t) infinite;
      }

      /* Press. The hand ramps force steadily, but the dome stiffens less
         and less toward its peak, so travel creeps and then quickens — a
         mild ease-in over 600ms to 5.07. Past the peak the dome's
         resistance falls away while the hand's force does not, and the key
         crosses the rest of its travel in 45ms, accelerating into the board:
         the plot leaves the curve and runs flat across, at the force the
         finger was already applying. Release mirrors it lower down — the
         dome slides back to its valley, then pops the key up in 50ms — and
         the two jumps at two different forces are the hysteresis that keeps
         a resting finger from chattering the switch. */
      @keyframes travel {
        0%,
        11.11% {
          --_k: 0;
          animation-timing-function: cubic-bezier(0.4, 0, 0.7, 0.6);
        }
        27.78% {
          --_k: 5.07;
          animation-timing-function: cubic-bezier(0.5, 0.05, 0.9, 0.5);
        }
        29.03%,
        41.67% {
          --_k: 10;
          animation-timing-function: cubic-bezier(0.45, 0, 0.55, 1);
        }
        50% {
          --_k: 7.887;
          animation-timing-function: cubic-bezier(0.55, 0, 0.6, 1);
        }
        51.39% {
          --_k: 1.134;
          animation-timing-function: cubic-bezier(0.23, 1, 0.32, 1);
        }
        58.33%,
        100% {
          --_k: 0;
        }
      }

      @keyframes dot {
        0%,
        11.11% {
          offset-distance: 0%;
          animation-timing-function: cubic-bezier(0.4, 0, 0.7, 0.6);
        }
        27.78% {
          offset-distance: 27.5%;
          animation-timing-function: cubic-bezier(0.5, 0.05, 0.9, 0.5);
        }
        29.03%,
        41.67% {
          offset-distance: 48.93%;
          animation-timing-function: cubic-bezier(0.45, 0, 0.55, 1);
        }
        50% {
          offset-distance: 63.25%;
          animation-timing-function: cubic-bezier(0.55, 0, 0.6, 1);
        }
        51.39% {
          offset-distance: 92.61%;
          animation-timing-function: cubic-bezier(0.23, 1, 0.32, 1);
        }
        58.33%,
        100% {
          offset-distance: 100%;
        }
      }

      @keyframes grip {
        0%,
        5.56% {
          opacity: 0;
          transform: scale(0.6);
          animation-timing-function: cubic-bezier(0.23, 1, 0.32, 1);
        }
        11.11%,
        51.39% {
          opacity: 0.4;
          transform: scale(1);
          animation-timing-function: cubic-bezier(0.23, 1, 0.32, 1);
        }
        55.56%,
        100% {
          opacity: 0;
          transform: translateY(-6px) scale(0.6);
        }
      }

      /* Lands with the snap and lets go slowly — fast in, slow out reads as
         "that was it", and a faint wash stays so the area can be read. */
      @keyframes surplus {
        0%,
        27.78% {
          opacity: 0;
          animation-timing-function: cubic-bezier(0.23, 1, 0.32, 1);
        }
        29.44% {
          opacity: 0.34;
          animation-timing-function: cubic-bezier(0.23, 1, 0.32, 1);
        }
        44.44%,
        88.89% {
          opacity: 0.14;
        }
        94.44%,
        100% {
          opacity: 0;
        }
      }

      @keyframes foot-in {
        0%,
        29.03% {
          opacity: 0;
        }
        32.5%,
        91.67% {
          opacity: 1;
        }
        96.11%,
        100% {
          opacity: 0;
        }
      }

      @media (prefers-reduced-motion: reduce) {
        /* The press goes; the plot stays. The key sits bottomed, the dot
           waits at the end of the jump, and the surplus is shaded. */
        .rig,
        .dot,
        .tip,
        .surplus,
        .foot {
          animation: none;
        }

        .rig {
          --_k: 10;
        }

        .dot {
          offset-distance: 48.93%;
        }

        .surplus {
          opacity: 0.2;
        }

        .foot {
          opacity: 1;
        }
      }
    </style>
  </head>
  <body>
    <div
      class="rig"
      role="img"
      aria-label="A key on a metal snap dome, pressed and released, beside its force against travel curve. Force climbs to a peak, then the dome buckles and the key jumps to the bottom at constant force; on release it slides back and pops up at a lower force. The shaded area between the jump and the curve is the click."
    >
      <p class="cap">latch · snap dome</p>
      <div class="key">
        <div class="dome">
          <svg viewBox="0 0 36 16" preserveAspectRatio="none" aria-hidden="true">
            <path d="M0,16 C6,0 30,0 36,16" />
          </svg>
        </div>
        <i class="board"></i>
        <div class="keycap">
          <div class="face"></div>
          <i class="tip"></i>
        </div>
      </div>
      <div class="plot">
        <svg viewBox="0 0 200 80" width="200" height="80" aria-hidden="true">
          <path class="axis" d="M10,2 L10,72 L196,72" />
          <path class="surplus" d="M82,22 C96,22 106,54 122,54 C136,54 146,40 152,22 Z" />
          <path
            class="curve"
            d="M10,72 C30,46 62,22 82,22 C96,22 106,54 122,54 C136,54 146,40 152,22 L156,6"
          />
          <line class="jump" x1="82" y1="22" x2="152" y2="22" />
          <line class="jump" x1="122" y1="54" x2="26.1" y2="54" />
        </svg>
        <span class="axl f">force</span>
        <span class="axl x">travel</span>
        <i class="dot"></i>
      </div>
      <p class="foot">the key leaves the curve — that gap is the click</p>
    </div>
  </body>
</html>

The variant family

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