GLITCH LAB v1.0 ezolab.dev / lab instrument SYS: READY ✦ Holiday cards

Lab/ Guides/ Technique

How to Add a Pause Between CSS Animation Loops

animation-delay only waits once. Three ways to rest between loops of a CSS animation, each with a live demo: hold keyframes, an @property clock with a --pause variable, and a few lines of JS for random pauses.

/#animation

Guide // TechniqueLive demos inside
Contents [9]
  1. The quick answer
  2. Why animation-delay does not repeat
  3. Way 1: hold the last keyframe
  4. Way 2: a clock on @property, the pause in a variable
  5. Way 3: JavaScript, when the pause should be random
  6. Which one to use
  7. Gotchas
  8. Accessibility
  9. FAQ

You want an animation to play, rest for a few seconds, and play again — a glitch that fires now and then, a logo that wiggles every 5 seconds. The obvious animation-delay does not do it: it waits once, before the first run, and then the loop repeats back to back. Here are three ways to get a real delay between iterations of a CSS animation, from the classic trick to a pause you can change with one variable. Every example has a live demo right on the page, so you can watch the difference before you copy the code.

The quick answer

Make the pause part of the animation. Set the duration to motion + pause, finish the motion early in the keyframes and hold still until 100%:

.ping {
  /* 0.6 s of motion + 2 s of rest = 2.6 s */
  animation: ping 2.6s ease-out infinite;
}

@keyframes ping {
  0% { transform: translateX(0); }
  6% { transform: translateX(14px); }
  12% { transform: translateX(-8px); }
  18% { transform: translateX(4px); }
  23%, 100% { transform: translateX(0); }   /* 0.6 / 2.6 ≈ 23% */
}

Live example — the same 0.6 s jitter, without and with a pause:

Top: animation-delay only, no rest. Bottom: 2 s pause inside the cycle

That works everywhere. Its weak spot: the pause is baked into the percentages. The second way below fixes that.

Why animation-delay does not repeat

animation-delay is applied once, when the animation starts. After that, infinite plays iteration after iteration with no gap. There is no animation-iteration-delay property in CSS.

animation-delay: 2s — it waits once, then jitters with no rest

Way 1: hold the last keyframe

The duration becomes the whole cycle: motion plus rest. Squeeze the motion into the first part of the keyframes and repeat the end state up to 100%.

The math: motion ÷ (motion + pause). For 0.6 s of motion and 2 s of rest, the motion ends at 0.6 / 2.6 ≈ 23%.

Motion in the first 23% of a 2.6 s cycle, then 2 s of rest

Good for one fixed rhythm. But change the pause from 2 s to 4 s and every percentage has to be recalculated, and two elements with different pauses need two copies of the keyframes. Keyframe selectors cannot use var(), so a variable will not help here.

Way 2: a clock on @property, the pause in a variable

This is the trick every effect on this site uses. Instead of animating the motion directly, animate one number — a clock --t that runs from 0 to 1 once per cycle. Then compute the motion from the clock with calc().

@property --t {
  syntax: "<number>";
  inherits: true;
  initial-value: 0;
}
@keyframes clock {
  to { --t: 1; }
}

.ping {
  --run: 0.6;   /* seconds of motion */
  --pause: 2;   /* seconds of rest */
  animation: clock calc((var(--run) + var(--pause)) * 1s) linear infinite;
  /* progress of the motion: 0 → 1, then it stays 1 for the pause */
  --p: clamp(0, var(--t) * (var(--run) + var(--pause)) / var(--run), 1);
  /* a damped swing: two back-and-forths that lose strength */
  transform: translateX(calc(16px * (1 - var(--p)) * sin(var(--p) * 720deg)));
}

Why it works, step by step:

  1. @property registers --t as a number. A normal custom property cannot be animated — it jumps. A registered one is interpolated frame by frame.
  2. The clock takes run + pause seconds and runs linear, so --t is simply "where we are in the cycle".
  3. --p stretches the first part of the cycle to 0 → 1 and clamp() holds it at 1 for the rest. That is the pause — computed, not typed into keyframes.
  4. The motion is any formula of --p. Here sin() makes the swing and (1 - p) fades it out, so it settles smoothly instead of stopping dead.
The same rhythm from a clock: change --pause and nothing else

Now one rule serves any rhythm. Set the pause per element — no new keyframes:

One rule, three pauses: 0.5 s, 1.5 s and 3 s

The same clock drives the real effects here. In Chromatic Wave it swings the red and blue copies of the word, then rests for --gw-pause:

[FX_01] Pure CSSChromatic WaveRGB split text effect in pure CSS: red and blue copies of a word swing apart like a damped wave, then snap back. Tweak it and copy the code.Tweak it live & copy the code →

Glitch Text uses it to open short "tear windows" inside the cycle, and Glitch Image starts the clock on :hover, so the photo glitches, calms down, and glitches again while the cursor stays on it. In Typewriter one clock runs the whole cycle — type, hold, erase, pause.

Way 3: JavaScript, when the pause should be random

A fixed rhythm starts to feel mechanical. A broken neon tube does not blink every 4 seconds — it blinks about every 4 seconds. CSS has no random numbers yet, so here a few lines of JS are the honest tool:

const sign = document.querySelector(".sign");

function flicker() {
  sign.classList.remove("is-flickering");
  void sign.offsetWidth;   // restart the CSS animation
  sign.classList.add("is-flickering");
  // next one in 4 s ± 40%
  setTimeout(flicker, 4000 * (0.6 + Math.random() * 0.8));
}
setTimeout(flicker, 4000);

The animation itself stays in CSS (one run, no infinite); JS only decides when. Keep the base pause in a CSS variable and read it with getComputedStyle(sign).getPropertyValue("--pause"), so designers still tune it in the stylesheet. That is how Neon Sign picks a random letter and a random moment:

[FX_02] CSS + JSNeon SignFlickering neon text in CSS: glass tubes that burn, spark and now and then die, like a real broken sign. Copy the code or download MP4, GIF or PNG.Tweak it live & copy the code →

Which one to use

You need Use
One element, fixed rhythm, oldest browsers Way 1: hold keyframes
Pause as a setting, many elements, smooth motion Way 2: @property clock
Random or event-driven pauses Way 3: a few lines of JS

Gotchas

  • Browser support. @property works in Chrome and Edge 85+, Safari 16.4+ and Firefox 128+; sin() in all current browsers. Without @property the clock does not move, --p stays 0 and the element simply stands still — a safe fallback.
  • inherits: true matters when pseudo-elements or children read the clock (::before, ::after). With false they see only the initial value.
  • Animate transform and opacity. The clock itself is cheap, but whatever you compute from it is repainted every frame — avoid width, top or big box-shadow there.
  • Easing lives in the formula. The clock must run linear; shape the motion with sin(), a power (var(--p) * var(--p)) or clamp() windows.
  • Way 1 with ease-out applies the easing between each pair of keyframes, not to the whole cycle. If the motion looks mushy, set animation-timing-function inside the keyframes.

Accessibility

A pause already makes motion calmer, but people who turn on "reduce motion" should get none:

@media (prefers-reduced-motion: reduce) {
  .ping { animation: none; }
}

With the clock, animation: none leaves --t at 0, so the element rests in its start pose. Effects on this site show a "Play anyway" button instead of forcing motion.

FAQ

How do I add a delay between iterations of a CSS animation?

Include the delay in the animation duration and keep the last keyframe until 100% (Way 1), or animate an @property clock and compute a pause with clamp() (Way 2). animation-delay alone only delays the first iteration.

Is there an animation-iteration-delay property?

No. CSS has animation-delay (once, before the first run) and animation-iteration-count (how many runs), but nothing for the gap between runs. With animation-iteration-count: infinite the rest has to live inside the cycle — hold keyframes or a clock, as above.

Can I see a live example of a CSS animation with a pause?

Yes — every demo on this page is live, and the effect cards above show the same trick in finished effects. On each effect page the pause is a setting: change it and watch the rhythm change, then copy the code.

Can I pause an animation with animation-play-state?

animation-play-state: paused freezes an animation where it is, for example on :hover. It is a pause button, not a rhythm: it does not add rest between loops by itself.

How do I make the pause random?

CSS cannot pick random numbers yet, so use a short setTimeout loop that restarts the animation (Way 3). For a pseudo-random look without JS, give several elements clocks with different, unrelated pauses — like 1.3 s, 2.1 s and 3.4 s — so they never sync up.

Does this work for transitions?

Transitions run once per state change, so there is nothing to repeat. transition-delay delays the start of each change; for a looping rest use an animation.