AI CSS Animations

Pop Rotating Words

The old word shrinks away and the next one pops in with a springy overshoot and a small tilt. The bounce is a cubic-bezier that overshoots 1, set on the keyframe where the pop starts.

Also known as: scale pop word swap, bouncy word rotator, pop in text rotate.

Make it pop. fun. yours.

HTML

<div class="txt-pop-rotating-words">Make it
  <span class="txt-pop-rotating-words-words">
    <span style="--i: 0">pop.</span>
    <span style="--i: 1">fun.</span>
    <span style="--i: 2">yours.</span>
  </span>
</div>

CSS

.txt-pop-rotating-words {
  --c: var(--txt-color, #3b82f6);
  font-size: var(--txt-size, 32px);
  font-family: system-ui, sans-serif;
  font-weight: 700;
  line-height: 1.2;
  display: flex;
  align-items: baseline;
  gap: 0.28em;
  white-space: nowrap;}
.txt-pop-rotating-words-words {
  display: inline-grid;
  color: var(--c);
}
.txt-pop-rotating-words-words span {
  grid-area: 1 / 1;
  justify-self: start;
  transform-origin: 40% 70%;
  /* 3 words x 1.8s = 5.4s */
  animation: txt-pop-rotating-words-pop 5.4s linear infinite;
  animation-delay: calc(var(--i) * 1.8s - 5.9s);
}
.txt-pop-rotating-words-words span:not(:first-child) {
  opacity: 0;
}
@keyframes txt-pop-rotating-words-pop {
  0% {
    opacity: 0; transform: scale(0.3) rotate(-10deg);
    animation-timing-function: cubic-bezier(0.34, 1.7, 0.6, 1);
  }
  9.26% { opacity: 1; transform: scale(1) rotate(0); }
  29.63% {
    opacity: 1; transform: scale(1) rotate(0);
    animation-timing-function: cubic-bezier(0.5, 0, 0.75, 0);
  }
  33.33%, 100% { opacity: 0; transform: scale(0.4) rotate(6deg); }
}

@media (prefers-reduced-motion: reduce) {
  .txt-pop-rotating-words, .txt-pop-rotating-words *, .txt-pop-rotating-words::before, .txt-pop-rotating-words::after, .txt-pop-rotating-words *::before, .txt-pop-rotating-words *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

Customizing this snippet

  • Color: set --txt-color on the element or a parent. Currently previewing #3b82f6.
  • Font size: set --txt-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 40px.
  • Speed: change the duration on the transition or animation shorthand. Staggered delays are relative, so they keep their rhythm.
  • Reduced motion: the rule at the end of the CSS turns the motion off for people who asked their OS for less of it. Keep it.

Similar text animations