AI CSS Animations

Heartbeat Text Animation

A double beat, lub then dub, ripples through the letters with a soft glow on each thump. The stagger is only 40ms per letter, so it reads as one heartbeat rather than a wave.

Also known as: beating heart text, lub dub text animation, pulsing letters css.

HTML

<div class="txt-heartbeat-text" aria-label="Made with love"><span aria-hidden="true"><span style="--i: 0">M</span><span style="--i: 1">a</span><span style="--i: 2">d</span><span style="--i: 3">e</span><span style="--i: 4">&nbsp;</span><span style="--i: 5">w</span><span style="--i: 6">i</span><span style="--i: 7">t</span><span style="--i: 8">h</span><span style="--i: 9">&nbsp;</span><span style="--i: 10">l</span><span style="--i: 11">o</span><span style="--i: 12">v</span><span style="--i: 13">e</span></span></div>

CSS

.txt-heartbeat-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);
  letter-spacing: 0.02em;}
.txt-heartbeat-text span span {
  display: inline-block;
  animation: txt-heartbeat-text-beat 1.4s ease-in-out infinite;
  animation-delay: calc(var(--i) * 0.04s);
}
@keyframes txt-heartbeat-text-beat {
  0%, 38%, 100% { transform: scale(1); text-shadow: 0 0 0 transparent; }
  8%  { transform: scale(1.2); text-shadow: 0 0 0.3em color-mix(in srgb, var(--c) 60%, transparent); }
  16% { transform: scale(1); text-shadow: 0 0 0.1em color-mix(in srgb, var(--c) 25%, transparent); }
  25% { transform: scale(1.1); text-shadow: 0 0 0.25em color-mix(in srgb, var(--c) 45%, transparent); }
}

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