Back to the library

Overlay — dialog pop

Variant: Dialog pop

A confirmation dialog arriving over a page. The scrim leads by a beat and does most of the work — it recolours everything behind it to say "this is inert now", so the panel only has to show up: scale from 0.96, never zero, centred because a dialog is anchored to nothing. The 179ms exit is faster than the 252ms enter, since leaving should never outstay the decision.

overlaytransitioncontrol

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>Overlay — dialog pop</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 cycle: enter, hold long enough to read, leave, rest.
           Every duration in the document runs off --t. */
        --cycle: 5.6s;
        --t: calc(var(--cycle) / var(--speed));

        --ease-out: cubic-bezier(0.23, 1, 0.32, 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);
      }

      /* The mini viewport the choreography happens inside. Everything is
         clipped to it, so the animation reads at any stage size. */
      .frame {
        position: relative;
        width: clamp(220px, 46vw, 340px);
        height: min(68vh, 74vw, 230px);
        border-radius: calc(12px * var(--round));
        background: var(--paper);
        border: 1px solid color-mix(in srgb, var(--slate) 10%, transparent);
        overflow: hidden;
      }

      .page {
        position: absolute;
        inset: 0;
        padding: 16px;
        display: grid;
        gap: 10px;
        align-content: start;
      }

      .bar {
        height: 10px;
        border-radius: 5px;
        background: var(--oat);
      }

      .page .head {
        display: flex;
        align-items: center;
        gap: 8px;
        margin-bottom: 4px;
      }

      .page .dot {
        width: 14px;
        height: 14px;
        border-radius: 50%;
        background: var(--clay);
        flex: none;
      }

      /* The scrim carries most of the meaning: it recolours the whole page to
         say "everything behind this is inert now". The panel only has to
         arrive. It leads the panel by ~30ms so the room dims before the
         thing enters it. */
      .scrim {
        position: absolute;
        inset: 0;
        background: color-mix(in srgb, var(--slate) 34%, transparent);
        opacity: 0;
        animation: scrim var(--t) linear infinite;
      }

      @keyframes scrim {
        0%,
        8% {
          opacity: 0;
          animation-timing-function: ease;
        }
        12.5%,
        56% {
          opacity: 1;
          animation-timing-function: ease;
        }
        60.5%,
        100% {
          opacity: 0;
        }
      }

      /* A dialog is anchored to nothing, so it scales from its own centre —
         the one overlay where transform-origin: center is correct. It starts
         at 0.96, never zero, and the 179ms exit is faster than the 252ms
         enter: leaving should never outstay the decision. */
      .dialog {
        position: absolute;
        left: 50%;
        top: 50%;
        width: min(72%, 220px);
        transform: translate(-50%, -50%) scale(0.96);
        opacity: 0;
        background: var(--ivory);
        border-radius: calc(10px * var(--round));
        padding: 14px;
        box-shadow: 0 12px 32px color-mix(in srgb, var(--slate) 18%, transparent);
        animation: dialog var(--t) linear infinite;
      }

      @keyframes dialog {
        0%,
        8.5% {
          opacity: 0;
          transform: translate(-50%, -50%) scale(0.96);
          animation-timing-function: var(--ease-out);
        }
        13%,
        55.5% {
          opacity: 1;
          transform: translate(-50%, -50%) scale(1);
          animation-timing-function: ease;
        }
        58.7%,
        100% {
          opacity: 0;
          transform: translate(-50%, -50%) scale(0.97);
        }
      }

      /* The copy rides in ~50ms behind the surface with a 3px rise — enough
         that the panel visibly brings its contents, not enough to read as a
         second entrance. */
      .inner {
        display: grid;
        gap: 9px;
        animation: inner var(--t) linear infinite;
      }

      @keyframes inner {
        0%,
        9.4% {
          opacity: 0;
          transform: translateY(3px);
          animation-timing-function: var(--ease-out);
        }
        13.8%,
        100% {
          opacity: 1;
          transform: translateY(0);
        }
      }

      .dialog .title {
        font-size: 12.5px;
        font-weight: 600;
        letter-spacing: -0.01em;
      }

      .dialog .bar {
        height: 7px;
        background: var(--oat);
      }

      .actions {
        display: flex;
        justify-content: flex-end;
        gap: 6px;
        margin-top: 3px;
      }

      .btn {
        font-size: 11px;
        font-weight: 550;
        line-height: 1;
        padding: 6px 10px;
        border-radius: calc(6px * var(--round));
        background: var(--oat);
      }

      .btn.primary {
        background: var(--clay);
        color: var(--ivory);
      }

      @media (prefers-reduced-motion: reduce) {
        /* The states still trade places; only the travel and scale go. */
        .dialog {
          animation: dialog-rm var(--t) linear infinite;
        }

        .inner {
          animation: none;
          opacity: 1;
          transform: none;
        }

        @keyframes dialog-rm {
          0%,
          8.5% {
            opacity: 0;
            transform: translate(-50%, -50%);
            animation-timing-function: ease;
          }
          13%,
          55.5% {
            opacity: 1;
            transform: translate(-50%, -50%);
            animation-timing-function: ease;
          }
          58.7%,
          100% {
            opacity: 0;
            transform: translate(-50%, -50%);
          }
        }
      }
    </style>
  </head>
  <body>
    <div
      class="frame"
      role="img"
      aria-label="A confirmation dialog opening over a page and closing again"
    >
      <div class="page">
        <div class="head">
          <span class="dot"></span>
          <span class="bar" style="width: 42%"></span>
        </div>
        <span class="bar" style="width: 88%"></span>
        <span class="bar" style="width: 74%"></span>
        <span class="bar" style="width: 81%"></span>
        <span class="bar" style="width: 56%"></span>
      </div>
      <div class="scrim"></div>
      <div class="dialog">
        <div class="inner">
          <span class="title">Delete project?</span>
          <span class="bar" style="width: 92%"></span>
          <span class="bar" style="width: 64%"></span>
          <div class="actions">
            <span class="btn">Cancel</span>
            <span class="btn primary">Delete</span>
          </div>
        </div>
      </div>
    </div>
  </body>
</html>

The variant family

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