Back to the library

Interpret swap, handoff

Variant: Handoff

The in-place translation swap with the two texts never overlapping: the original clears completely in 140ms, then the translation rises in over 200ms. Use it for scripts with very different shapes, such as Latin next to CJK or Arabic, where a crossfade would briefly show two layers of text on top of each other. The total time is about the same as the cascade (340ms against about 370ms). Only the order changes: the outgoing text finishes leaving before the new text starts to arrive.

translatetext-swapsequencedstate-changei18n

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>Interpret swap — 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; /* include ONLY if at least one border-radius is wrapped below */
  --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
     (#d97757 / #b85c3e / #788c5d / #b04a3f). */
  --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 — every duration in the document runs off --t. */
  --cycle: 4.8s; /* the authored master loop */
  --t: calc(var(--cycle) / var(--speed));

  --ease-out: cubic-bezier(0.23, 1, 0.32, 1); /* include only if used */

  --_stagger: calc(0ms / var(--speed));
  --_tint: color-mix(in oklch, var(--clay) 18%, var(--paper));
  --_edge: color-mix(in oklch, var(--clay) 45%, var(--paper));
}

* { box-sizing: border-box; }
html, body { margin: 0; }

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

.card {
  width: min(340px, 88vw);
  padding: clamp(16px, 5vw, 24px);
  background: var(--paper);
  border: 1px solid var(--oat);
  border-radius: calc(14px * var(--round));
  display: grid;
  gap: clamp(12px, 3.5vw, 18px);
}

.langs { display: flex; align-items: center; gap: 8px; }
.langs svg { opacity: 0.45; }

.pill {
  position: relative;
  isolation: isolate;
  padding: 4px 10px;
  border: 1px solid var(--oat);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  line-height: 1.2;
}
.pill::before {
  content: "";
  position: absolute;
  inset: -1px;
  z-index: -1;
  border-radius: inherit;
  background: var(--_tint);
  border: 1px solid var(--_edge);
}
.pill--src::before { animation: src-fade var(--t) var(--ease-out) infinite both; }
.pill--tgt::before { animation: tgt-fade var(--t) var(--ease-out) infinite both; }

.phrase {
  display: grid;
  margin: 0;
  font-size: clamp(18px, 5.4vw, 24px);
  font-weight: 500;
  line-height: 1.3;
  letter-spacing: -0.01em;
}
.line { grid-area: 1 / 1; }

.w {
  display: inline-block;
  animation-duration: var(--t);
  animation-timing-function: var(--ease-out);
  animation-iteration-count: infinite;
  animation-fill-mode: both;
  animation-delay: calc(var(--_i) * var(--_stagger));
}
.src .w { animation-name: src-fade, src-move; }
.tgt .w { animation-name: tgt-fade, tgt-move; }

/* 1% = 48ms. Exit 140ms, then enter 200ms starting the moment the exit ends — no overlap, no dead air. */
@keyframes src-fade {
  0%, 37.5% { opacity: 1; }
  40.42%, 90.42% { opacity: 0; }
  94.58%, 100% { opacity: 1; }
}
@keyframes src-move {
  0%, 37.5% { transform: translateY(0); filter: blur(0); }
  40.42%, 90.41% { transform: translateY(-0.35em); filter: blur(3px); }
  90.42% { transform: translateY(0.35em); filter: blur(3px); }
  94.58%, 100% { transform: translateY(0); filter: blur(0); }
}
@keyframes tgt-fade {
  0%, 40.42% { opacity: 0; }
  44.58%, 87.5% { opacity: 1; }
  90.42%, 100% { opacity: 0; }
}
@keyframes tgt-move {
  0%, 40.42% { transform: translateY(0.35em); filter: blur(3px); }
  44.58%, 87.5% { transform: translateY(0); filter: blur(0); }
  90.42% { transform: translateY(-0.35em); filter: blur(3px); }
  90.43%, 100% { transform: translateY(0.35em); filter: blur(3px); }
}

@media (max-width: 380px) {
  .card { padding: 16px; }
  .phrase { font-size: 19px; }
}

@media (prefers-reduced-motion: reduce) {
  .w, .pill::before { animation-duration: calc(var(--cycle) * 2 / var(--speed)); }
  .w { animation-delay: calc(var(--_i) * var(--_stagger) * 2); }
  .src .w { animation-name: src-fade; }
  .tgt .w { animation-name: tgt-fade; }
}
</style>
</head>
<body>
  <div class="card">
    <div class="langs">
      <span class="pill pill--src">EN</span>
      <svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true"><path d="M3 8h10M9.5 4.5 13 8l-3.5 3.5" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>
      <span class="pill pill--tgt">ES</span>
    </div>
    <p class="phrase">
      <span class="line src" lang="en"><span class="w" style="--_i:0">Where</span> <span class="w" style="--_i:1">is</span> <span class="w" style="--_i:2">the</span> <span class="w" style="--_i:3">station?</span></span>
      <span class="line tgt" lang="es"><span class="w" style="--_i:0">¿Dónde</span> <span class="w" style="--_i:1">está</span> <span class="w" style="--_i:2">la</span> <span class="w" style="--_i:3">estación?</span></span>
    </p>
  </div>
</body>
</html>

The variant family

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