AI CSS Animations

Levitating Text Effect

Each letter hovers on its own rhythm above a soft shadow that shrinks and fades as the letter rises. The shadow counter-moves with the same timing, so it stays on the floor.

Also known as: floating letters, hovering text with shadow, anti gravity text.

HTML

<div class="txt-levitating-text" aria-label="Anti-gravity"><span aria-hidden="true"><span style="--i: 0">A</span><span style="--i: 1">n</span><span style="--i: 2">t</span><span style="--i: 3">i</span><span style="--i: 4">-</span><span style="--i: 5">g</span><span style="--i: 6">r</span><span style="--i: 7">a</span><span style="--i: 8">v</span><span style="--i: 9">i</span><span style="--i: 10">t</span><span style="--i: 11">y</span></span></div>

CSS

.txt-levitating-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;
  color: var(--c);
  padding-bottom: 0.3em;}
.txt-levitating-text span span {
  position: relative;
  display: inline-block;
  animation: txt-levitating-text-lift 3.2s ease-in-out infinite;
  /* 0.7s steps scatter the phases so letters float independently */
  animation-delay: calc(var(--i) * -0.7s);
}
.txt-levitating-text span span::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -0.32em;
  height: 0.16em;
  border-radius: 50%;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--c) 55%, transparent), transparent);
  animation: txt-levitating-text-shadow 3.2s ease-in-out infinite;
  animation-delay: calc(var(--i) * -0.7s);
}
@keyframes txt-levitating-text-lift {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-0.3em); }
}
@keyframes txt-levitating-text-shadow {
  0%, 100% { transform: translateY(0) scaleX(1); opacity: 1; }
  50%      { transform: translateY(0.3em) scaleX(0.55); opacity: 0.35; }
}

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