Two diagonal strokes draw an X across the button, then thicken until they cover it. The individual rotate and scale properties let length and thickness run on separate timings.
Also known as: x shaped fill hover, diagonal cross button, x fill button.
<button class="hfx-cross-fill">Close deal</button>
.hfx-cross-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: 2px solid var(--c);
background: transparent;
color: var(--c);
transition: color 0.2s ease 0.1s;
}
.hfx-cross-fill::before,
.hfx-cross-fill::after {
content: "";
position: absolute;
left: -15%;
top: -15%;
z-index: -1;
width: 130%;
height: 130%;
background: var(--c);
rotate: 17deg;
scale: 1 0.07;
transform: scaleX(0);
transition: scale 0.25s cubic-bezier(0.33, 1, 0.68, 1), transform 0.2s cubic-bezier(0.5, 0, 0.75, 0) 0.2s;
}
.hfx-cross-fill::after { rotate: -17deg; }
.hfx-cross-fill:is(:hover, :focus-visible) {
background-color: var(--c); /* hides the hairline where the fill meets the border */
color: #fff;
transition: color 0.2s ease 0.32s, background-color 0s 0.65s;
}
.hfx-cross-fill:is(:hover, :focus-visible)::before,
.hfx-cross-fill:is(:hover, :focus-visible)::after {
scale: 1 1;
transform: scaleX(1);
transition: transform 0.25s cubic-bezier(0.25, 1, 0.5, 1), scale 0.35s cubic-bezier(0.65, 0, 0.35, 1) 0.24s;
}
.hfx-cross-fill:is(:hover, :focus-visible)::after { transition-delay: 0.08s, 0.3s; }
@media (prefers-reduced-motion: reduce) {
.hfx-cross-fill, .hfx-cross-fill *, .hfx-cross-fill::before, .hfx-cross-fill::after, .hfx-cross-fill *::before, .hfx-cross-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.