AI CSS Animations

Swing In Letters Text Effect

Each letter drops in hanging from its top edge and swings back and forth like a sign on a hook, losing a little each pass. A damped pendulum written as alternating ease-in-out keyframes.

Also known as: hanging letters animation, swing in text css, pendulum letters entrance.

Hang in there

HTML

<div class="txt-swing-in-letters" aria-label="Hang in there"><span style="--i: 0">H</span><span style="--i: 1">a</span><span style="--i: 2">n</span><span style="--i: 3">g</span><span style="--i: 4">&nbsp;</span><span style="--i: 5">i</span><span style="--i: 6">n</span><span style="--i: 7">&nbsp;</span><span style="--i: 8">t</span><span style="--i: 9">h</span><span style="--i: 10">e</span><span style="--i: 11">r</span><span style="--i: 12">e</span></div>

CSS

.txt-swing-in-letters {
  --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);
  white-space: nowrap;}
.txt-swing-in-letters span {
  display: inline-block;
  transform-origin: 50% 0;
  animation: txt-swing-in-letters-swing 1.5s ease-in-out calc(var(--i) * 80ms) both;
}
@keyframes txt-swing-in-letters-swing {
  0%   { opacity: 0; transform: translateY(-0.5em) rotate(50deg); }
  22%  { opacity: 1; transform: translateY(0) rotate(-28deg); }
  42%  { transform: translateY(0) rotate(16deg); }
  60%  { transform: translateY(0) rotate(-8deg); }
  75%  { transform: translateY(0) rotate(4deg); }
  89%  { transform: translateY(0) rotate(-1.5deg); }
  100% { opacity: 1; transform: translateY(0) rotate(0); }
}

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