The button rises half an em while a soft oval shadow stays on the ground below it, so it reads as floating rather than sliding. The shadow is a radial gradient that moves down as the button goes up.
Also known as: hvr-float-shadow, float on hover css, levitate button hover.
<button class="hfx-float-shadow">Book a call</button>
.hfx-float-shadow {
--c: var(--hfx-color, #3b82f6);
display: inline-flex;
align-items: center;
gap: 0.5em;
padding: 0.7em 1.6em;
border-radius: 0.5em;
font: 600 var(--hfx-size, 16px) system-ui, sans-serif;
cursor: pointer;
border: 0;
background: var(--c);
color: #fff;
position: relative;
transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);}
.hfx-float-shadow::before {
content: "";
position: absolute;
top: 100%;
left: 10%;
right: 10%;
height: 0.8em;
background: radial-gradient(closest-side, color-mix(in srgb, var(--c) 55%, transparent), transparent);
opacity: 0;
transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1), opacity 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
pointer-events: none;
}
.hfx-float-shadow:is(:hover, :focus-visible) {
transform: translateY(-0.5em);
}
.hfx-float-shadow:is(:hover, :focus-visible)::before {
opacity: 1;
transform: translateY(0.65em) scaleX(0.85);
}
@media (prefers-reduced-motion: reduce) {
.hfx-float-shadow, .hfx-float-shadow *, .hfx-float-shadow::before, .hfx-float-shadow::after, .hfx-float-shadow *::before, .hfx-float-shadow *::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.