A text button with a short underline that grows up and out into a full rounded fill on hover. One clip-path inset() that interpolates its edges and its corner radius together.
Also known as: underline grow button, border bottom fill hover, text button fill.
<button class="hfx-underline-to-fill">Read the docs</button>
.hfx-underline-to-fill {
--c: var(--hfx-color, #3b82f6);
position: relative;
isolation: isolate;
overflow: hidden;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 0.5em;
padding: 0.75em 1.75em;
border-radius: 0.5em;
font: 600 var(--hfx-size, 16px)/1.2 system-ui, sans-serif;
white-space: nowrap;
cursor: pointer;
border: 0;
background: transparent;
color: var(--c);
transition: color 0.25s ease 0.12s;
}
.hfx-underline-to-fill::before {
content: "";
position: absolute;
inset: 0;
z-index: -1;
background: var(--c);
clip-path: inset(calc(100% - 0.62em) 1.75em 0.42em round 0.1em);
transition: clip-path 0.4s cubic-bezier(0.65, 0, 0.35, 1);
}
.hfx-underline-to-fill:is(:hover, :focus-visible) { color: #fff; }
.hfx-underline-to-fill:is(:hover, :focus-visible)::before {
clip-path: inset(0 round 0.5em);
}
@media (prefers-reduced-motion: reduce) {
.hfx-underline-to-fill, .hfx-underline-to-fill *, .hfx-underline-to-fill::before, .hfx-underline-to-fill::after, .hfx-underline-to-fill *::before, .hfx-underline-to-fill *::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.