A tinted block sits offset behind the outline; on hover it snaps into the frame with a little overshoot and turns solid. The block is a pseudo-element that only moves and recolors.
Also known as: offset background button, retro offset hover, fill snap button.
<button class="hfx-offset-fill">View our work</button>
.hfx-offset-fill {
--c: var(--hfx-color, #3b82f6);
position: relative;
isolation: isolate;
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.05s;
}
.hfx-offset-fill::before {
content: "";
position: absolute;
inset: -2px;
z-index: -1;
border-radius: inherit;
background: color-mix(in srgb, var(--c) 22%, transparent);
transform: translate(0.35em, 0.35em);
transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), background-color 0.25s ease;
}
.hfx-offset-fill:is(:hover, :focus-visible) { color: #fff; }
.hfx-offset-fill:is(:hover, :focus-visible)::before {
background: var(--c);
transform: translate(0, 0);
}
@media (prefers-reduced-motion: reduce) {
.hfx-offset-fill, .hfx-offset-fill *, .hfx-offset-fill::before, .hfx-offset-fill::after, .hfx-offset-fill *::before, .hfx-offset-fill *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}The same effect using Tailwind utility classes. No custom CSS or config needed.
<button class="group relative isolate rounded-lg border-2 border-blue-500 px-7 py-3 font-semibold text-blue-500 transition-colors duration-200 hover:text-white"> <span class="absolute -inset-[2px] -z-10 translate-x-1.5 translate-y-1.5 rounded-lg bg-blue-500/20 transition duration-300 ease-[cubic-bezier(0.34,1.56,0.64,1)] group-hover:translate-x-0 group-hover:translate-y-0 group-hover:bg-blue-500"></span> View our work </button>
--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.