AI CSS Animations

Letter Spacing Text Hover

The letters drift apart from the center on hover, like widening the tracking. Each span moves by its distance from the middle, so the width never changes and nothing around it reflows.

Also known as: tracking expand on hover, letter spacing animation, text spread hover.

SPACE

HTML

<div class="hfx-text-spread-letters" aria-label="Space"><span style="--i: 0">S</span><span style="--i: 1">P</span><span style="--i: 2">A</span><span style="--i: 3">C</span><span style="--i: 4">E</span></div>

CSS

.hfx-text-spread-letters {
  --c: var(--hfx-color, #3b82f6);
  font-size: calc(var(--hfx-size, 16px) * 2.5);
  font-family: system-ui, sans-serif;
  font-weight: 800;
  line-height: 1.15;
  cursor: default;
  --n: 5; /* number of letters */
  display: inline-flex;
  font-weight: 700;}
.hfx-text-spread-letters span {
  display: block;
  transition: transform 0.5s cubic-bezier(0.22, 1, 0.36, 1), color 0.5s ease;
}
.hfx-text-spread-letters:hover span {
  color: var(--c);
  transform: translateX(calc((var(--i) - (var(--n) - 1) / 2) * 0.18em));
}

@media (prefers-reduced-motion: reduce) {
  .hfx-text-spread-letters, .hfx-text-spread-letters *, .hfx-text-spread-letters::before, .hfx-text-spread-letters::after, .hfx-text-spread-letters *::before, .hfx-text-spread-letters *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

Customizing this snippet

  • Color: set --hfx-color on the element or a parent. Currently previewing #3b82f6.
  • Base size: set --hfx-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 16px.
  • 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 hover effects