The underline swells upward into a solid block behind the text, which flips to white. One pseudo-element scaled on Y from the bottom edge, so it animates on the compositor.
Also known as: underline fill up hover, link background slide up, thick underline to highlight.
<a class="hfx-link-underline-fill" href="#">Join the beta</a>
.hfx-link-underline-fill {
--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;
isolation: isolate;
padding: 0 0.2em;
color: inherit;
transition: color 0.3s ease;}
.hfx-link-underline-fill::before {
content: "";
position: absolute;
inset: 0;
z-index: -1;
border-radius: 0.15em;
background: var(--c);
transform: scaleY(0.08);
transform-origin: bottom;
transition: transform 0.35s cubic-bezier(0.65, 0, 0.35, 1);
}
.hfx-link-underline-fill:is(:hover, :focus-visible) { color: #fff; }
.hfx-link-underline-fill:is(:hover, :focus-visible)::before { transform: scaleY(1); }
@media (prefers-reduced-motion: reduce) {
.hfx-link-underline-fill, .hfx-link-underline-fill *, .hfx-link-underline-fill::before, .hfx-link-underline-fill::after, .hfx-link-underline-fill *::before, .hfx-link-underline-fill *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}The same effect using Tailwind utility classes. No custom CSS or config needed.
<a href="#" class="relative isolate px-1 text-xl font-semibold transition-colors duration-300 before:absolute before:inset-0 before:-z-10 before:origin-bottom before:scale-y-[0.08] before:rounded-sm before:bg-blue-500 before:transition-transform before:duration-300 hover:text-white hover:before:scale-y-100"> Join the beta </a>
--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.