AI CSS Animations

Balloon Text Animation

Each letter rides its own balloon on a string, bobbing and swaying from the end of the string at its own pace. Balloon colors are mixed from your accent, and the knot and string are pseudo-elements.

Also known as: balloon letters, floating balloon text, party text animation.

HTML

<div class="txt-balloon-text" aria-label="Hooray"><span aria-hidden="true"><span style="--i: 0">H</span><span style="--i: 1">o</span><span style="--i: 2">o</span><span style="--i: 3">r</span><span style="--i: 4">a</span><span style="--i: 5">y</span></span></div>

CSS

.txt-balloon-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.95em;}
.txt-balloon-text span span {
  --b: var(--c);
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 1.3em;
  height: 1.55em;
  margin: 0 0.04em;
  border-radius: 50% 50% 48% 48% / 56% 56% 44% 44%;
  font-size: 0.8em;
  color: #fff;
  background: radial-gradient(circle at 32% 28%, color-mix(in srgb, var(--b) 50%, #fff) 0, var(--b) 45%, color-mix(in srgb, var(--b) 80%, #000) 100%);
  /* sway from the bottom of the string */
  transform-origin: 50% calc(100% + 1.1em);
  animation: txt-balloon-text-drift 3.2s ease-in-out infinite;
  animation-delay: calc(var(--i) * -0.9s);
}
.txt-balloon-text span span:nth-child(3n + 2) { --b: color-mix(in oklch, var(--c) 45%, #ec4899); }
.txt-balloon-text span span:nth-child(3n) { --b: color-mix(in oklch, var(--c) 35%, #f59e0b); }
/* knot */
.txt-balloon-text span span::before {
  content: "";
  position: absolute;
  top: 97%;
  left: 50%;
  width: 0.22em;
  height: 0.14em;
  margin-left: -0.11em;
  background: var(--b);
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}
/* string */
.txt-balloon-text span span::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  width: 1px;
  height: 1.1em;
  background: color-mix(in srgb, var(--c) 50%, transparent);
}
@keyframes txt-balloon-text-drift {
  0%, 100% { transform: translateY(0) rotate(-5deg); }
  50%      { transform: translateY(-0.18em) rotate(5deg); }
}

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