AI CSS Animations

Wipe Rotating Text

A thin bar sweeps across the word slot, wiping the old word away and drawing the new one in behind it, like a video wipe transition. Both words and the bar share one clip-path easing curve.

Also known as: clip path word swap, wipe transition text, text slider wipe.

Launch faster today anywhere

HTML

<div class="txt-wipe-rotating-text">Launch
  <span class="txt-wipe-rotating-text-words">
    <span style="--i: 0">faster</span>
    <span style="--i: 1">today</span>
    <span style="--i: 2">anywhere</span>
  <i class="txt-wipe-rotating-text-edge" aria-hidden="true"></i>
  </span>
</div>

CSS

.txt-wipe-rotating-text {
  --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-wipe-rotating-text-words {
  position: relative;
  display: inline-grid;
  color: var(--c);
}
.txt-wipe-rotating-text-words span {
  grid-area: 1 / 1;
  /* 3 words x 2.2s = 6.6s */
  animation: txt-wipe-rotating-text-wipe 6.6s cubic-bezier(0.65, 0, 0.35, 1) infinite;
  animation-delay: calc(var(--i) * 2.2s - 6.6s);
}
.txt-wipe-rotating-text-words span:not(:first-child) {
  clip-path: inset(0 100% 0 0);
}
/* the edge layer is as wide as the slot, so translateX(100%) crosses it exactly */
.txt-wipe-rotating-text-edge {
  position: absolute;
  inset: 0;
  opacity: 0;
  animation: txt-wipe-rotating-text-edge 2.2s cubic-bezier(0.65, 0, 0.35, 1) infinite;
}
.txt-wipe-rotating-text-edge::before {
  content: "";
  position: absolute;
  left: -0.04em;
  top: 0.06em;
  bottom: 0.06em;
  width: 0.08em;
  border-radius: 0.04em;
  background: currentColor;
}
@keyframes txt-wipe-rotating-text-wipe {
  0%, 24.24% { clip-path: inset(0 0 0 0); }
  33.33%       { clip-path: inset(0 0 0 100%); }
  90.91%       { clip-path: inset(0 100% 0 0); }
  100%         { clip-path: inset(0 0 0 0); }
}
@keyframes txt-wipe-rotating-text-edge {
  0%, 72.68% { transform: translateX(0); opacity: 0; }
  72.73%      { transform: translateX(0); opacity: 1; }
  88%         { opacity: 1; }
  100%        { transform: translateX(100%); opacity: 0; }
}

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