AI CSS Animations

Text Decoration Underline Animation

A real text-decoration underline rises into place with a little bounce and thickens as it lands. Because it is the native underline, it follows the text across line breaks and skips descenders.

Also known as: text-underline-offset animation, animated text decoration, multi line underline animation.

Real underlines wrap across lines

HTML

<div class="txt-text-decoration-underline">Real underlines wrap across lines</div>

CSS

.txt-text-decoration-underline {
  --c: var(--txt-color, #3b82f6);
  font-size: var(--txt-size, 32px);
  font-family: system-ui, sans-serif;
  font-weight: 700;
  line-height: 1.2;
  max-width: 9.5em;
  text-align: center;
  text-decoration-line: underline;
  text-decoration-color: transparent;
  text-decoration-thickness: 0.02em;
  text-underline-offset: 0.6em;
  animation: txt-text-decoration-underline-rise 0.9s cubic-bezier(0.34, 1.56, 0.64, 1) 0.3s forwards;}
@keyframes txt-text-decoration-underline-rise {
  to {
    text-decoration-color: var(--c);
    text-decoration-thickness: 0.08em;
    text-underline-offset: 0.12em;
  }
}

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