An inline link inside a paragraph whose underline draws line by line when the link wraps, finishing one row before starting the next. It is background-size on an inline element.
Also known as: animated underline multiple lines, wrapping link underline, background size underline.
Before you ship, read our field guide to accessible motion and reduced motion defaults for the details.
<p class="hfx-link-multiline-underline">Before you ship, read our <a href="#">field guide to accessible motion and reduced motion defaults</a> for the details.</p>
.hfx-link-multiline-underline {
--c: var(--hfx-color, #3b82f6);
max-width: 17em;
margin: 0;
font: 400 calc(var(--hfx-size, 16px) * 1.1)/1.6 system-ui, sans-serif;
}
.hfx-link-multiline-underline a {
color: var(--c);
font-weight: 600;
text-decoration: none;
background:
linear-gradient(var(--c) 0 0) 0 100% / 0 0.1em no-repeat,
linear-gradient(color-mix(in srgb, var(--c) 28%, transparent) 0 0) 0 100% / 100% 0.1em no-repeat;
transition: background-size 0.7s cubic-bezier(0.65, 0, 0.35, 1);
}
.hfx-link-multiline-underline a:is(:hover, :focus-visible) {
background-size: 100% 0.1em, 100% 0.1em;
}
@media (prefers-reduced-motion: reduce) {
.hfx-link-multiline-underline, .hfx-link-multiline-underline *, .hfx-link-multiline-underline::before, .hfx-link-multiline-underline::after, .hfx-link-multiline-underline *::before, .hfx-link-multiline-underline *::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.
<p class="max-w-xs text-lg leading-relaxed"> Before you ship, read our <a href="#" class="bg-gradient-to-r from-blue-500 to-blue-500 bg-[length:0%_2px] bg-left-bottom bg-no-repeat font-semibold text-blue-500 transition-[background-size] duration-700 hover:bg-[length:100%_2px]">field guide to accessible motion and reduced motion defaults</a> for the details. </p>
--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.