Back to the library

Interpret swap, single beat

Variant: Single beat

The same in-place swap between original and translated text, done as one quick crossfade: every word leaves in 120ms and the new line arrives in 160ms, all at once. Use it when people flip between languages often, for example in a chat thread where each message has its own toggle, and a cascade would feel slow. There's no stagger because a single short beat reads as instant feedback instead of a reveal.

translatetext-swapcrossfadestate-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 — single beat</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. Swap at 37.5% (1.8s), revert at 87.5% (4.2s). Exit 120ms, enter 160ms. */
@keyframes src-fade {
  0%, 37.5% { opacity: 1; }
  40%, 87.5% { opacity: 0; }
  90.83%, 100% { opacity: 1; }
}
@keyframes src-move {
  0%, 37.5% { transform: translateY(0); filter: blur(0); }
  40%, 87.49% { transform: translateY(-0.35em); filter: blur(3px); }
  87.5% { transform: translateY(0.35em); filter: blur(3px); }
  90.83%, 100% { transform: translateY(0); filter: blur(0); }
}
@keyframes tgt-fade {
  0%, 37.5% { opacity: 0; }
  40.83%, 87.5% { opacity: 1; }
  90%, 100% { opacity: 0; }
}
@keyframes tgt-move {
  0%, 37.5% { transform: translateY(0.35em); filter: blur(3px); }
  40.83%, 87.5% { transform: translateY(0); filter: blur(0); }
  90% { transform: translateY(-0.35em); filter: blur(3px); }
  90.01%, 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.