A dotted underline whose dots stretch into dashes and close up into a solid line on hover. The dash length is a registered @property, so the gradient stop can transition.
Also known as: dotted underline css, dotted to solid underline, dashed underline hover.
<a class="hfx-link-dotted-underline" href="#">Terms of service</a>
@property --hfx-link-dotted-underline-dash {
syntax: "<percentage>";
inherits: false;
initial-value: 35%;
}
.hfx-link-dotted-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;
--hfx-link-dotted-underline-dash: 35%;
color: inherit;
padding-bottom: 0.25em;
background: linear-gradient(90deg, var(--c) var(--hfx-link-dotted-underline-dash), transparent 0) 0 100% / 0.32em 0.11em repeat-x;
transition: --hfx-link-dotted-underline-dash 0.45s cubic-bezier(0.65, 0, 0.35, 1), color 0.3s ease;}
.hfx-link-dotted-underline:is(:hover, :focus-visible) {
--hfx-link-dotted-underline-dash: 100%;
color: var(--c);
}
@media (prefers-reduced-motion: reduce) {
.hfx-link-dotted-underline, .hfx-link-dotted-underline *, .hfx-link-dotted-underline::before, .hfx-link-dotted-underline::after, .hfx-link-dotted-underline *::before, .hfx-link-dotted-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.