AI CSS Animations

Zero Gravity Floating Text

Gravity switches off, the letters drift apart, each turning slowly on its own path picking up your accent, then they float back into line. Each letter carries its drift in three custom properties.

Also known as: floating text effect, floating letters animation, weightless text css.

HTML

<div class="txt-zero-gravity-text" aria-label="weightless"><span aria-hidden="true"><span style="--i: 0; --x: -0.22em; --y: -0.34em; --r: -18deg">w</span><span style="--i: 1; --x: 0.08em; --y: 0.28em; --r: 14deg">e</span><span style="--i: 2; --x: -0.04em; --y: -0.52em; --r: 32deg">i</span><span style="--i: 3; --x: 0.14em; --y: 0.22em; --r: -12deg">g</span><span style="--i: 4; --x: -0.1em; --y: -0.4em; --r: 20deg">h</span><span style="--i: 5; --x: 0.2em; --y: 0.42em; --r: -26deg">t</span><span style="--i: 6; --x: -0.14em; --y: -0.3em; --r: 40deg">l</span><span style="--i: 7; --x: 0.1em; --y: 0.34em; --r: -10deg">e</span><span style="--i: 8; --x: -0.2em; --y: -0.24em; --r: 24deg">s</span><span style="--i: 9; --x: 0.24em; --y: 0.38em; --r: -30deg">s</span></span></div>

CSS

.txt-zero-gravity-text {
  --c: var(--txt-color, #3b82f6);
  font-size: calc(var(--txt-size, 32px) * 2);
  font-family: system-ui, sans-serif;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  letter-spacing: -0.01em;}
.txt-zero-gravity-text span span {
  display: inline-block;
  animation: txt-zero-gravity-text-drift 8s cubic-bezier(0.45, 0, 0.55, 1) infinite backwards;
  animation-delay: calc(var(--i) * 0.07s);
}
@keyframes txt-zero-gravity-text-drift {
  0%, 12%   { translate: 0 0; rotate: 0deg; color: currentColor; }
  48%       { translate: var(--x) var(--y); rotate: var(--r); color: color-mix(in srgb, var(--c) 80%, currentColor); }
  64%       { translate: calc(var(--x) * 0.7) calc(var(--y) * 1.18); rotate: calc(var(--r) * 1.25); color: var(--c); }
  90%, 100% { translate: 0 0; rotate: 0deg; color: currentColor; }
}
@media (prefers-reduced-motion: reduce) {
  .txt-zero-gravity-text span span { animation: none; }
}

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