The top half fills from the left while the bottom half fills from the right, and they lock together in the middle. A small delay on the second half keeps it from feeling mirrored.
Also known as: opposite sweep hover, split sweep button, crossing fill button.
<button class="hfx-two-way-sweep">Compare plans</button>
.hfx-two-way-sweep {
--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: 2px solid var(--c);
background: transparent;
color: var(--c);
transition: color 0.25s ease 0.2s;
}
.hfx-two-way-sweep::before,
.hfx-two-way-sweep::after {
content: "";
position: absolute;
left: 0;
right: 0;
z-index: -1;
height: 51%;
background: var(--c);
transition: transform 0.45s cubic-bezier(0.65, 0, 0.35, 1);
}
.hfx-two-way-sweep::before {
top: 0;
transform: translateX(-101%);
}
.hfx-two-way-sweep::after {
bottom: 0;
transform: translateX(101%);
transition-delay: 0.07s;
}
.hfx-two-way-sweep:is(:hover, :focus-visible) {
background-color: var(--c); /* hides the hairline where the fill meets the border */
color: #fff;
transition: color 0.25s ease 0.2s, background-color 0s 0.55s;
}
.hfx-two-way-sweep:is(:hover, :focus-visible)::before,
.hfx-two-way-sweep:is(:hover, :focus-visible)::after {
transform: translateX(0);
}
@media (prefers-reduced-motion: reduce) {
.hfx-two-way-sweep, .hfx-two-way-sweep *, .hfx-two-way-sweep::before, .hfx-two-way-sweep::after, .hfx-two-way-sweep *::before, .hfx-two-way-sweep *::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.