Back to the library

Select — radio handoff

Variant: Radio

A radio group whose selection is passed from one option to the next, never dropped. The newly pressed ring dips to 88% in 80ms, and on the frame it bottoms out its dot starts growing from 40% over 200ms on ease-out. The old option starts leaving on that same frame and is gone in 80ms. A radio group must always have an answer: the handoff overlaps just enough that there is never a frame with none, and not long enough for two highlighted rows to read as a range. Row highlights are inset 2px so they never touch even during the overlap. The dot does not slide between rings: the options are separate choices, not positions on a track, and a travelling dot would suggest the in-between options were briefly selected. All three options run the same keyframes a third of a cycle apart, so the group cannot disagree with itself about which option is current. Reach for it in shipping options, plan pickers and settings, any small fixed set of mutually exclusive choices.

controltransitionmicro-interactionloop

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>Select — radio handoff</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 — 4.8s: three handoffs, one every 1.6s. Every option runs the
           same keyframes a third of a cycle apart, so the group can never
           disagree with itself about which option is current. */
        --cycle: 4.8s;
        --t: calc(var(--cycle) / var(--speed));

        --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
        --ease-accent: cubic-bezier(0.32, 0.72, 0, 1);
      }

      * {
        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);
      }

      .group {
        width: min(244px, 84vw);
        padding: 6px;
        border-radius: calc(12px * var(--round));
        background: var(--paper);
        box-shadow: 0 1px 2px color-mix(in srgb, var(--slate) 10%, transparent);
        font-size: clamp(13px, 4vw, 14px);
        letter-spacing: -0.01em;
      }

      .opt {
        position: relative;
        display: flex;
        align-items: center;
        gap: 11px;
        height: 42px;
        padding: 0 12px 0 10px;
      }

      .o1 {
        --_d: calc(var(--t) / -3);
      }

      .o2 {
        --_d: 0s;
      }

      .o3 {
        --_d: calc(var(--t) * -2 / 3);
      }

      .bg {
        position: absolute;
        inset: 2px 0;
        border-radius: calc(8px * var(--round));
        background: color-mix(in srgb, var(--clay) 10%, transparent);
        opacity: 0;
        animation: current var(--t) var(--_d) infinite;
      }

      .name {
        position: relative;
        font-weight: 500;
      }

      .eta {
        position: relative;
        margin-left: auto;
        font-variant-numeric: tabular-nums;
        color: color-mix(in srgb, var(--slate) 50%, transparent);
      }

      .radio {
        position: relative;
        flex: none;
        width: 20px;
        height: 20px;
        border-radius: 50%;
        box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--slate) 30%, transparent);
        animation: press var(--t) var(--_d) infinite;
      }

      .ring {
        position: absolute;
        inset: 0;
        border-radius: 50%;
        box-shadow: inset 0 0 0 1.5px var(--clay);
        opacity: 0;
        animation: current var(--t) var(--_d) infinite;
      }

      .dot {
        position: absolute;
        inset: 5px;
        border-radius: 50%;
        background: var(--clay);
        opacity: 0;
        transform: scale(0.4);
        animation: dot var(--t) var(--_d) infinite;
      }

      @keyframes press {
        0%,
        12.5% {
          transform: scale(1);
          animation-timing-function: var(--ease-accent);
        }
        14.17% {
          transform: scale(0.88);
          animation-timing-function: var(--ease-out);
        }
        17.92%,
        100% {
          transform: scale(1);
        }
      }

      /* The handoff starts on the frame the press bottoms out, 80ms in. The
         new dot grows from 40% over 200ms; the old option starts leaving on
         that same frame and is gone in 80ms. For those 80ms the old answer is
         fading under the new one, so there is never a frame with no answer
         and never long enough with two for them to read as a range. */
      @keyframes dot {
        0%,
        14.17% {
          opacity: 0;
          transform: scale(0.4);
          animation-timing-function: var(--ease-out);
        }
        18.33%,
        47.5% {
          opacity: 1;
          transform: scale(1);
          animation-timing-function: var(--ease-out);
        }
        49.17%,
        100% {
          opacity: 0;
          transform: scale(0.4);
        }
      }

      @keyframes current {
        0%,
        14.17% {
          opacity: 0;
          animation-timing-function: var(--ease-out);
        }
        16.25%,
        47.5% {
          opacity: 1;
          animation-timing-function: var(--ease-out);
        }
        49.17%,
        100% {
          opacity: 0;
        }
      }

      @media (prefers-reduced-motion: reduce) {
        .radio {
          animation: none;
        }

        .dot {
          animation-name: current;
          transform: none;
        }
      }
    </style>
  </head>
  <body>
    <div
      class="group"
      role="img"
      aria-label="A delivery-speed radio group whose selection hands off from one option to the next"
    >
      <div class="opt o1">
        <span class="bg"></span>
        <span class="radio"><span class="ring"></span><span class="dot"></span></span>
        <span class="name">Standard</span><span class="eta">4–6 days</span>
      </div>
      <div class="opt o2">
        <span class="bg"></span>
        <span class="radio"><span class="ring"></span><span class="dot"></span></span>
        <span class="name">Express</span><span class="eta">2 days</span>
      </div>
      <div class="opt o3">
        <span class="bg"></span>
        <span class="radio"><span class="ring"></span><span class="dot"></span></span>
        <span class="name">Overnight</span><span class="eta">Tomorrow</span>
      </div>
    </div>
  </body>
</html>

The variant family

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