AI CSS Animations

Rotating Text in a Pill Badge

The changing word sits in a solid pill that squishes like jelly each time the next word rolls up into place. A vertical track with a repeated first word keeps the loop free of jumps.

Also known as: rotating badge text, pill word carousel, animated tag headline.

Available on iOSAndroidthe web

HTML

<div class="txt-rotating-text-pill">Available on
  <span class="txt-rotating-text-pill-badge">
    <span class="txt-rotating-text-pill-window">
      <span class="txt-rotating-text-pill-track">
        <span>iOS</span><span>Android</span><span>the web</span><span aria-hidden="true">iOS</span>
      </span>
    </span>
  </span>
</div>

CSS

.txt-rotating-text-pill {
  --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: center;
  gap: 0.3em;
  white-space: nowrap;}
.txt-rotating-text-pill-badge {
  display: inline-block;
  padding: 0.1em 0.55em;
  border-radius: 2em;
  background: var(--c);
  color: #fff;
  animation: txt-rotating-text-pill-squish 2s ease-out infinite;
}
.txt-rotating-text-pill-window {
  display: block;
  height: 1.2em;
  overflow: hidden;
}
.txt-rotating-text-pill-track {
  display: flex;
  flex-direction: column;
  text-align: center;
  /* 3 words x 2s = 6s; the 4th span repeats the 1st so 100% matches 0% */
  animation: txt-rotating-text-pill-roll 6s cubic-bezier(0.34, 1.45, 0.64, 1) infinite;
}
.txt-rotating-text-pill-track span {
  height: 1.2em;
}
@keyframes txt-rotating-text-pill-roll {
  0%, 23.33%     { transform: translateY(0); }
  33.33%, 56.67% { transform: translateY(-1.2em); }
  66.67%, 90%     { transform: translateY(-2.4em); }
  100%            { transform: translateY(-3.6em); }
}
@keyframes txt-rotating-text-pill-squish {
  0%, 70% { transform: scale(1); }
  80%     { transform: scale(1.07, 0.9); }
  90%     { transform: scale(0.97, 1.05); }
  100%    { transform: scale(1); }
}

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