AI CSS Animations

Gradient Underline Link Hover

A thin two-tone gradient underline that thickens with a small spring and starts running along its length on hover. The second hue is rotated from the accent with relative color syntax.

Also known as: animated gradient underline, gradient border bottom link, colorful underline hover.

HTML

<a class="hfx-link-gradient-underline" href="#">See what shipped</a>

CSS

.hfx-link-gradient-underline {
  --c: var(--hfx-color, #3b82f6);
  position: relative;
  display: inline-block;
  color: var(--c);
  font: 600 calc(var(--hfx-size, 16px) * 1.25)/1.3 system-ui, sans-serif;
  text-decoration: none;
  padding-bottom: 0.3em;}
.hfx-link-gradient-underline::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 0.26em;
  border-radius: 1em;
  background: linear-gradient(90deg, var(--c), color-mix(in srgb, var(--c) 35%, #fff), var(--c)) 0 0 / 200% 100%;
  background-image: linear-gradient(90deg, var(--c), oklch(from var(--c) l c calc(h + 70)), var(--c));
  transform: scaleY(0.4);
  transform-origin: bottom;
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  animation: hfx-link-gradient-underline-run 1.6s linear infinite paused;
}
.hfx-link-gradient-underline:is(:hover, :focus-visible)::after {
  transform: scaleY(1);
  animation-play-state: running;
}
@keyframes hfx-link-gradient-underline-run {
  to { background-position: 200% 0; }
}

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

Underline Grow Link
Underline from Center Link
Highlighter Link
Slide Up Text Link