AI CSS Animations

Emoji Rotating Words

An emoji spins in with a springy pop and its word slides up a beat later, so each audience in the headline gets its own icon. The word runs 0.1s behind the emoji on the same keyframes clock.

Also known as: emoji text rotator, icon and word swap, rotating words with emoji.

Loved by designers developers founders

HTML

<div class="txt-emoji-rotating-words">Loved by
  <span class="txt-emoji-rotating-words-icons" aria-hidden="true">
    <span style="--i: 0">🎨</span>
    <span style="--i: 1">💻</span>
    <span style="--i: 2">🚀</span>
  </span>
  <span class="txt-emoji-rotating-words-words">
    <span style="--i: 0">designers</span>
    <span style="--i: 1">developers</span>
    <span style="--i: 2">founders</span>
  </span>
</div>

CSS

.txt-emoji-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-emoji-rotating-words-icons,
.txt-emoji-rotating-words-words {
  display: inline-grid;
}
.txt-emoji-rotating-words-words {
  margin-left: -0.05em;
  color: var(--c);
}
.txt-emoji-rotating-words-icons span,
.txt-emoji-rotating-words-words span {
  grid-area: 1 / 1;
  justify-self: start;
  /* 3 words x 2.2s = 6.6s; the word lags the emoji by 0.1s */
  animation: 6.6s infinite;
  animation-delay: calc(var(--i) * 2.2s - 7.4s);
}
.txt-emoji-rotating-words-icons span {
  animation-name: txt-emoji-rotating-words-spin;
}
.txt-emoji-rotating-words-words span {
  animation-name: txt-emoji-rotating-words-rise;
  animation-delay: calc(var(--i) * 2.2s - 7.3s);
}
.txt-emoji-rotating-words-icons span:not(:first-child),
.txt-emoji-rotating-words-words span:not(:first-child) {
  opacity: 0;
}
@keyframes txt-emoji-rotating-words-spin {
  0% {
    opacity: 0; transform: scale(0) rotate(-120deg);
    animation-timing-function: cubic-bezier(0.3, 1.5, 0.5, 1);
  }
  7.58% { opacity: 1; transform: scale(1) rotate(0); }
  29.55% {
    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) rotate(60deg); }
}
@keyframes txt-emoji-rotating-words-rise {
  0% {
    opacity: 0; transform: translateY(0.45em);
    animation-timing-function: cubic-bezier(0.2, 0.8, 0.2, 1);
  }
  6.82% { opacity: 1; transform: translateY(0); }
  28.79% {
    opacity: 1; transform: translateY(0);
    animation-timing-function: cubic-bezier(0.5, 0, 0.75, 0);
  }
  32.58%, 100% { opacity: 0; transform: translateY(-0.4em); }
}

@media (prefers-reduced-motion: reduce) {
  .txt-emoji-rotating-words, .txt-emoji-rotating-words *, .txt-emoji-rotating-words::before, .txt-emoji-rotating-words::after, .txt-emoji-rotating-words *::before, .txt-emoji-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