Back to the library

Night sky — twinkle by altitude

Variant: Twinkle

Two dozen stars on one set of keyframes, and the depth of the flicker is set by how much air each one shines through: the floor sits near 0.9 of full brightness overhead and 0.34 at the horizon, and the period shortens from about five seconds to about one on the way down. That single rule is what turns a scatter of blinking dots into a sky with a horizon in it. The stops are uneven and linear between them, because scintillation is noise and anything eased reads as a pulse. One bright star low in the east also flashes colour in steps — dispersion jumps, it does not blend — and one planet holds perfectly still, because a disc averages out the air a point cannot; it is the control that makes everything around it read as twinkling. Reach for it on an empty state or an after-hours surface where the page should feel calm but not stopped.

ambientloopstagger

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>Night sky — twinkle by altitude</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 — one scintillation at the zenith rate. A star's own period
           shortens with the air it shines through: a factor near 2 overhead,
           near 0.4 on the horizon, jittered so no two share a beat. */
        --cycle: 2.4s;
        --t: calc(var(--cycle) / var(--speed));

        /* The ground is a band the copy sits on, sized like the copy rather
           than like the panel, so the sky keeps whatever height is left. */
        --_ground: clamp(60px, 19vw, 80px);
        --_dot: 2.4px;
      }

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

      /* Lifted off pure slate at the zenith and warmed toward the horizon, so
         the ground — which is pure slate — reads as nearer than the sky. */
      .panel {
        position: relative;
        overflow: hidden;
        width: min(392px, calc(100% - 26px));
        height: clamp(150px, 46vw, 214px);
        border-radius: calc(16px * var(--round));
        background: linear-gradient(
          to bottom,
          color-mix(in oklab, var(--slate) 93%, var(--ivory)) 0%,
          color-mix(in oklab, var(--slate) 84%, var(--clay-d)) 100%
        );
      }

      .sky {
        position: absolute;
        inset: 0 0 var(--_ground) 0;
      }

      .ground {
        position: absolute;
        right: 0;
        bottom: 0;
        left: 0;
        display: block;
        width: 100%;
        height: calc(var(--_ground) + 8px);
        fill: var(--slate);
      }

      .copy {
        position: absolute;
        right: clamp(16px, 4.6vw, 24px);
        bottom: clamp(12px, 3.8vw, 20px);
        left: clamp(16px, 4.6vw, 24px);
        color: var(--ivory);
      }

      .head {
        font-size: clamp(15px, 4.4vw, 19px);
        font-weight: 600;
        letter-spacing: -0.01em;
      }

      .sub {
        margin-top: 3px;
        font-size: clamp(11.5px, 3.3vw, 13px);
        color: color-mix(in srgb, var(--ivory) 58%, transparent);
      }

      .sky > i {
        position: absolute;
        top: var(--_y);
        left: var(--_x);
        width: calc(var(--_dot) * var(--_s));
        height: calc(var(--_dot) * var(--_s));
        border-radius: 50%;
        translate: -50% -50%;
        background: var(--ivory);
        opacity: var(--_b);
        --_floor: var(--_lo);
        animation: scint calc(var(--t) * var(--_d)) linear infinite;
        animation-delay: calc(var(--t) * var(--_d) * var(--_lag) * -1);
      }

      /* Scintillation is noise, not a wave: uneven stops, linear between them,
         so the flicker never resolves into a pulse. Depth is the floor — about
         0.9 overhead and 0.34 at the horizon, so the same keyframes are a
         shimmer up high and a sputter low down. */
      @keyframes scint {
        0%,
        100% {
          opacity: var(--_b);
        }
        14% {
          opacity: calc(var(--_b) * var(--_floor));
        }
        23% {
          opacity: calc(var(--_b) * (0.3 + 0.7 * var(--_floor)));
        }
        41% {
          opacity: calc(var(--_b) * (0.2 + 0.8 * var(--_floor)));
        }
        57% {
          opacity: var(--_b);
        }
        72% {
          opacity: calc(var(--_b) * var(--_floor));
        }
        86% {
          opacity: calc(var(--_b) * (0.5 + 0.5 * var(--_floor)));
        }
      }

      /* The one bright star low in the east also flashes colour — the
         atmosphere splitting it like a prism, which is what Sirius does on a
         winter horizon. Stepped, because dispersion jumps between colours
         rather than blending through them. */
      .sky > .low {
        --_s: 1.7;
        --_b: 1;
        --_lag: 0.3;
        --_lo: 0.34;
        --_d: 0.46;
        background: var(--ivory);
        animation:
          scint calc(var(--t) * var(--_d)) linear infinite,
          prism calc(var(--t) * 0.71) steps(1) infinite;
        animation-delay: calc(var(--t) * var(--_d) * var(--_lag) * -1), 0s;
      }

      @keyframes prism {
        0%,
        100% {
          background: var(--ivory);
        }
        19% {
          background: var(--clay);
        }
        31% {
          background: var(--ivory);
        }
        62% {
          background: var(--olive);
        }
        70% {
          background: var(--ivory);
        }
      }

      /* A planet is a disc, not a point, and a disc averages out the air in
         front of it. It holds perfectly still — the control in the experiment,
         and the reason the stars around it read as twinkling at all. */
      .sky > .planet {
        --_s: 1.6;
        background: color-mix(in oklab, var(--ivory) 78%, var(--clay));
        opacity: 1;
        animation: none;
      }

      @media (prefers-reduced-motion: reduce) {
        /* Slower and shallower: the floor lifts halfway to steady and every
           period stretches by 2.5x, so the horizon still sputters more than the
           zenith but nothing flickers faster than about once a second. The
           prism stops — a colour flash is the sharpest thing on the card. */
        .sky > i {
          --_floor: calc(0.5 + 0.5 * var(--_lo));
          animation-duration: calc(var(--t) * var(--_d) * 2.5);
        }

        .sky > .low {
          animation: scint calc(var(--t) * var(--_d) * 2.5) linear infinite;
          animation-delay: calc(var(--t) * var(--_d) * 2.5 * var(--_lag) * -1);
        }

        .sky > .planet {
          animation: none;
        }
      }
    </style>
  </head>
  <body>
    <div class="panel">
      <div class="sky" aria-hidden="true">
        <i
          style="
            --_x: 31.7%;
            --_y: 5.3%;
            --_s: 0.83;
            --_b: 0.76;
            --_lo: 0.91;
            --_d: 1.69;
            --_lag: 0.01;
          "
        ></i>
        <i
          style="
            --_x: 28%;
            --_y: 59.3%;
            --_s: 1.2;
            --_b: 0.91;
            --_lo: 0.65;
            --_d: 1.16;
            --_lag: 0.39;
          "
        ></i>
        <i
          style="
            --_x: 85.1%;
            --_y: 45.8%;
            --_s: 0.8;
            --_b: 0.76;
            --_lo: 0.74;
            --_d: 1.75;
            --_lag: 0.5;
          "
        ></i>
        <i
          style="
            --_x: 87%;
            --_y: 81.1%;
            --_s: 0.89;
            --_b: 0.79;
            --_lo: 0.48;
            --_d: 0.89;
            --_lag: 0.62;
          "
        ></i>
        <i
          style="
            --_x: 9.6%;
            --_y: 18.2%;
            --_s: 0.77;
            --_b: 0.74;
            --_lo: 0.88;
            --_d: 1.88;
            --_lag: 0.65;
          "
        ></i>
        <i
          style="
            --_x: 23.4%;
            --_y: 12.6%;
            --_s: 1.28;
            --_b: 0.94;
            --_lo: 0.9;
            --_d: 1.82;
            --_lag: 0.52;
          "
        ></i>
        <i
          style="
            --_x: 46.7%;
            --_y: 45.7%;
            --_s: 0.66;
            --_b: 0.7;
            --_lo: 0.74;
            --_d: 1.39;
            --_lag: 0.7;
          "
        ></i>
        <i
          style="
            --_x: 64%;
            --_y: 6.7%;
            --_s: 1.03;
            --_b: 0.84;
            --_lo: 0.91;
            --_d: 2.09;
            --_lag: 0.2;
          "
        ></i>
        <i
          style="
            --_x: 49.7%;
            --_y: 34.2%;
            --_s: 0.78;
            --_b: 0.75;
            --_lo: 0.81;
            --_d: 1.68;
            --_lag: 0.96;
          "
        ></i>
        <i
          style="
            --_x: 60.9%;
            --_y: 93.5%;
            --_s: 0.96;
            --_b: 0.82;
            --_lo: 0.36;
            --_d: 0.6;
            --_lag: 0.97;
          "
        ></i>
        <i
          style="
            --_x: 74.3%;
            --_y: 73.4%;
            --_s: 1.04;
            --_b: 0.85;
            --_lo: 0.54;
            --_d: 0.88;
            --_lag: 0.97;
          "
        ></i>
        <i
          style="
            --_x: 52.4%;
            --_y: 10%;
            --_s: 0.92;
            --_b: 0.8;
            --_lo: 0.9;
            --_d: 2.04;
            --_lag: 0.84;
          "
        ></i>
        <i
          style="
            --_x: 81.3%;
            --_y: 19.9%;
            --_s: 0.79;
            --_b: 0.75;
            --_lo: 0.87;
            --_d: 1.82;
            --_lag: 0.75;
          "
        ></i>
        <i
          style="
            --_x: 4.2%;
            --_y: 42.6%;
            --_s: 1.26;
            --_b: 0.93;
            --_lo: 0.76;
            --_d: 1.59;
            --_lag: 0.28;
          "
        ></i>
        <i
          style="
            --_x: 4.8%;
            --_y: 5.2%;
            --_s: 0.79;
            --_b: 0.75;
            --_lo: 0.91;
            --_d: 1.8;
            --_lag: 0.68;
          "
        ></i>
        <i
          style="
            --_x: 93.6%;
            --_y: 45.9%;
            --_s: 0.94;
            --_b: 0.81;
            --_lo: 0.74;
            --_d: 1.54;
            --_lag: 0.07;
          "
        ></i>
        <i
          style="
            --_x: 18.7%;
            --_y: 74.1%;
            --_s: 1.23;
            --_b: 0.92;
            --_lo: 0.54;
            --_d: 1.12;
            --_lag: 0.05;
          "
        ></i>
        <i
          style="
            --_x: 40.9%;
            --_y: 20.4%;
            --_s: 0.67;
            --_b: 0.71;
            --_lo: 0.87;
            --_d: 1.83;
            --_lag: 0.76;
          "
        ></i>
        <i
          style="
            --_x: 35.1%;
            --_y: 47.8%;
            --_s: 1.12;
            --_b: 0.88;
            --_lo: 0.73;
            --_d: 1.67;
            --_lag: 0.94;
          "
        ></i>
        <i
          style="
            --_x: 5.4%;
            --_y: 58.2%;
            --_s: 1.01;
            --_b: 0.83;
            --_lo: 0.66;
            --_d: 1.42;
            --_lag: 0.47;
          "
        ></i>
        <i
          style="
            --_x: 47%;
            --_y: 74.7%;
            --_s: 1.08;
            --_b: 0.86;
            --_lo: 0.53;
            --_d: 0.87;
            --_lag: 0.66;
          "
        ></i>
        <i
          style="
            --_x: 39.2%;
            --_y: 75.9%;
            --_s: 1.21;
            --_b: 0.91;
            --_lo: 0.52;
            --_d: 0.9;
            --_lag: 0.92;
          "
        ></i>
        <i
          style="
            --_x: 15.9%;
            --_y: 31.8%;
            --_s: 0.75;
            --_b: 0.73;
            --_lo: 0.82;
            --_d: 1.88;
            --_lag: 0.38;
          "
        ></i>
        <i
          style="
            --_x: 68%;
            --_y: 48.6%;
            --_s: 0.9;
            --_b: 0.79;
            --_lo: 0.72;
            --_d: 1.65;
            --_lag: 0.21;
          "
        ></i>
        <i class="planet" style="--_x: 63%; --_y: 26%"></i>
        <i class="low" style="--_x: 18%; --_y: 90%"></i>
      </div>
      <svg class="ground" viewBox="0 0 400 88" preserveAspectRatio="none" aria-hidden="true">
        <path d="M0 14 C 46 6, 92 4, 140 10 S 228 20, 276 12 S 360 2, 400 9 V 88 H 0 Z" />
      </svg>
      <div class="copy">
        <p class="head">Clear tonight</p>
        <p class="sub">Ambient sky. Nothing here reports state.</p>
      </div>
    </div>
  </body>
</html>

The variant family

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