AI CSS Animations

3D Flip Card Rotating Text

The word sits on a card that flips over on its vertical axis to show the next word on its back, settling with a slight overshoot. Every word is one face with backface-visibility hidden.

Also known as: flip text animation css, card flip word swap, rotateY text rotator.

Book a demo call tour

HTML

<div class="txt-flip-card-rotating-text">Book a
  <span class="txt-flip-card-rotating-text-card">
    <span style="--i: 0">demo</span>
    <span style="--i: 1">call</span>
    <span style="--i: 2">tour</span>
  </span>
</div>

CSS

.txt-flip-card-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: center;
  gap: 0.3em;
  white-space: nowrap;}
.txt-flip-card-rotating-text-card {
  display: inline-grid;
}
.txt-flip-card-rotating-text-card span {
  grid-area: 1 / 1;
  padding: 0.04em 0.45em 0.08em;
  border-radius: 0.24em;
  background: var(--c);
  color: #fff;
  text-align: center;
  backface-visibility: hidden;
  /* 3 words x 2s = 6s */
  animation: txt-flip-card-rotating-text-flip 6s cubic-bezier(0.45, 0, 0.25, 1.3) infinite;
  animation-delay: calc(var(--i) * 2s - 6s);
}
.txt-flip-card-rotating-text-card span:not(:first-child) {
  opacity: 0;
}
/* out: 0 to -180deg; in: 180deg to 0, on the same beat, so the pair reads as one card */
@keyframes txt-flip-card-rotating-text-flip {
  0%, 21.67% { transform: perspective(6em) rotateY(0); }
  0%, 32% { opacity: 1; }
  33.33% { transform: perspective(6em) rotateY(-180deg); opacity: 0; }
  33.34% { transform: perspective(6em) rotateY(180deg); opacity: 0; }
  34%, 100% { opacity: 1; }
  88.33% { transform: perspective(6em) rotateY(180deg); }
  100%   { transform: perspective(6em) rotateY(0); }
}

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