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.
<a class="hfx-link-gradient-underline" href="#">See what shipped</a>
.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;
}
}--hfx-color on the element or a parent.
Currently previewing #3b82f6.--hfx-size. Every other dimension is in
em, so the whole thing scales together. Currently previewing 16px.transition or animation
shorthand. Staggered delays are relative, so they keep their rhythm.