Back to the library

Hover — spotlight tracks the pointer

Variant: Spotlight track

A card lit from where the pointer is: a soft wash under the hand and, on one shared timeline, a brighter light on the stretch of hairline border nearest to it — a second, wider disc masked down to a 1px ring and driven by the same keyframes, so the border always lights directly under the brightest part of the card. A whole border lighting up is a selected state; the nearest stretch lighting up is a hover. The light trails the pointer by about 96ms, each leg the pointer’s own leg shifted later, the lag that turns a cursor-locked decal into something that feels like it is being carried. When the pointer leaves, the light does not follow it out: pointer events stop at the edge, so it stops at the last point it was told about and fades there. That fade is 240ms against a 192ms arrival — the one place in the family where leaving is slower, because the light is an afterimage rather than the card’s state, and one that snaps off as the pointer clears the edge reads as a flicker. Reach for it on feature and pricing cards, a few at a time, where the surface is the affordance; it is too much for anything the user moves through quickly.

hovercontrolambientloop

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>Hover — spotlight tracks the pointer</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 — 3.8s, so 1% is 38ms. The pointer crosses into the card at
           14% and out of it at 70.9%; the light trails it by ~96ms
           the whole way and stops dead at the last point it was told about. */
        --cycle: 3.8s;
        --t: calc(var(--cycle) / var(--speed));

        --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
        --_hand: cubic-bezier(0.45, 0, 0.55, 1);

        --_wash: color-mix(in srgb, var(--clay) 20%, transparent);
        --_edge-lit: color-mix(in srgb, var(--clay) 85%, transparent);
        --_muted: color-mix(in srgb, var(--slate) 54%, transparent);
      }

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

      .stage {
        position: relative;
        width: 220px;
        height: 140px;
      }

      .card {
        position: absolute;
        inset: 0;
        overflow: hidden;
        border-radius: calc(14px * var(--round));
        background: var(--paper);
      }

      /* The hairline is its own layer so the lit copy of it can sit exactly
         on top: same box, same radius, masked down to the 1px ring. */
      .edge,
      .rim {
        position: absolute;
        inset: 0;
        border-radius: inherit;
      }

      .edge {
        border: 1px solid var(--oat);
      }

      .rim {
        padding: 1px;
        -webkit-mask:
          linear-gradient(var(--slate) 0 0) content-box,
          linear-gradient(var(--slate) 0 0);
        -webkit-mask-composite: xor;
        mask:
          linear-gradient(var(--slate) 0 0) content-box exclude,
          linear-gradient(var(--slate) 0 0);
      }

      .mover {
        position: absolute;
        left: 0;
        top: 0;
        transform: translate(11px, 140px);
        animation: track var(--t) infinite;
      }

      .light {
        position: absolute;
        left: -90px;
        top: -90px;
        width: 180px;
        height: 180px;
        border-radius: 50%;
        opacity: 0;
        animation: light var(--t) var(--ease-out) infinite;
      }

      .wash .light {
        background: radial-gradient(circle closest-side, var(--_wash), transparent);
      }

      /* The rim's light is a little wider than the wash and holds full
         strength for its inner quarter, because a 1px line needs more of it
         to register. Lighting the whole border at once is a selected state;
         lighting the stretch nearest the hand is a hover. */
      .rim .light {
        left: -100px;
        top: -100px;
        width: 200px;
        height: 200px;
        background: radial-gradient(circle closest-side, var(--_edge-lit) 25%, transparent);
      }

      .copy {
        position: relative;
        display: grid;
        gap: 4px;
        height: 100%;
        align-content: end;
        padding: 16px;
      }

      .copy small {
        font-size: 11.5px;
        color: var(--_muted);
      }

      .copy b {
        font-size: 15px;
        font-weight: 600;
        letter-spacing: -0.01em;
      }

      .copy span {
        font-size: 12px;
        color: var(--_muted);
      }

      /* One timeline for the wash and the rim, so the border always lights
         directly under the brightest part of the card. Each leg is the pointer's
         own leg shifted 2% later — the end legs on the matching slice of its
         sine — so the light is answering pointer events, never anticipating
         them. The top-right pass runs 18px from the edge so the rim has
         something to light. Curves are literal: var() in a keyframe is ignored. */
      @keyframes track {
        0%,
        16.5% {
          transform: translate(11px, 140px);
          animation-timing-function: cubic-bezier(0.25, 0.36, 0.55, 1);
        }
        25.3% {
          transform: translate(60px, 96px);
          animation-timing-function: cubic-bezier(0.45, 0, 0.55, 1);
        }
        48% {
          transform: translate(196px, 18px);
          animation-timing-function: cubic-bezier(0.45, 0, 0.55, 1);
        }
        63.2% {
          transform: translate(150px, 108px);
          animation-timing-function: cubic-bezier(0.42, 0, 0.8, 0.76);
        }
        73.4%,
        100% {
          transform: translate(220px, 117px);
        }
      }

      /* 192ms in, 240ms out — the one place in the family where leaving is
         slower than arriving. The light is not the card's state; it is an
         afterimage, and one that snaps off as the pointer clears the edge
         reads as a flicker rather than as the hand moving on. */
      @keyframes light {
        0%,
        14% {
          opacity: 0;
        }
        19.1%,
        70.9% {
          opacity: 1;
        }
        77.2%,
        100% {
          opacity: 0;
        }
      }

      .ghost {
        position: absolute;
        left: 0;
        top: 0;
        width: 14px;
        height: 18px;
        opacity: 0;
        transform: translate(-20px, 168px);
        animation:
          travel var(--t) var(--_hand) infinite,
          presence var(--t) var(--ease-out) infinite;
      }

      .arrow {
        display: block;
        width: 100%;
        height: 100%;
        fill: var(--slate);
        stroke: var(--ivory);
        stroke-width: 1.4;
        stroke-linejoin: round;
      }

      @keyframes travel {
        0%,
        7.6% {
          transform: translate(-20px, 168px);
        }
        22.7% {
          transform: translate(60px, 96px);
        }
        45.5% {
          transform: translate(196px, 18px);
        }
        60.6% {
          transform: translate(150px, 108px);
        }
        75.8%,
        85.9% {
          transform: translate(242px, 120px);
        }
        87.2%,
        100% {
          transform: translate(-20px, 168px);
        }
      }

      @keyframes presence {
        0% {
          opacity: 0;
        }
        5.1%,
        80.8% {
          opacity: 1;
        }
        85.9%,
        100% {
          opacity: 0;
        }
      }

      @media (prefers-reduced-motion: reduce) {
        /* The light stops following anything: it sits off the top-right corner
           and simply comes up and goes down, so the card still shows what its
           hover state looks like without anything sliding across it. */
        .ghost {
          display: none;
        }

        .mover {
          transform: translate(168px, 36px);
          animation: none;
        }

        .light {
          animation-duration: calc(var(--t) * 1.6);
        }
      }
    </style>
  </head>
  <body>
    <div
      class="stage"
      role="img"
      aria-label="A pointer wanders across a card; a soft light follows it a beat behind, and the stretch of border nearest the pointer lights with it; when the pointer leaves, the light stops at the edge it left by and fades out there"
    >
      <div class="card">
        <div class="wash">
          <span class="mover"><span class="light"></span></span>
        </div>
        <div class="edge"></div>
        <div class="rim">
          <span class="mover"><span class="light"></span></span>
        </div>
        <div class="copy">
          <small>Add-on</small>
          <b>Priority support</b>
          <span>Replies within the hour.</span>
        </div>
      </div>

      <span class="ghost">
        <svg class="arrow" viewBox="0 0 14 18">
          <path d="M1 1 L1 14.8 L4.5 11.6 L6.7 16.6 L9.3 15.4 L7.1 10.5 L11.8 10.3 Z" />
        </svg>
      </span>
    </div>
  </body>
</html>