The fill slides in carrying a second label and pushes the first one out, so 'Buy now' becomes the price. The hover label is aria-hidden, so screen readers hear the real one.
Also known as: show price on hover, push fill button, second label button.
<button class="hfx-price-reveal-fill"><span class="hfx-price-reveal-fill-label">Buy now</span><span class="hfx-price-reveal-fill-panel" aria-hidden="true">Only $49</span></button>
.hfx-price-reveal-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);
}
.hfx-price-reveal-fill-label,
.hfx-price-reveal-fill-panel {
transition: transform 0.45s cubic-bezier(0.65, 0, 0.35, 1);
}
.hfx-price-reveal-fill-panel {
position: absolute;
inset: 0;
display: grid;
place-items: center;
background: var(--c);
color: #fff;
transform: translateX(-101%);
}
.hfx-price-reveal-fill:is(:hover, :focus-visible) {
background-color: var(--c); /* hides the hairline where the fill meets the border */
transition: background-color 0s 0.45s;
}
.hfx-price-reveal-fill:is(:hover, :focus-visible) .hfx-price-reveal-fill-label {
transform: translateX(calc(100% + 1.8em));
}
.hfx-price-reveal-fill:is(:hover, :focus-visible) .hfx-price-reveal-fill-panel {
transform: translateX(0);
}
@media (prefers-reduced-motion: reduce) {
.hfx-price-reveal-fill, .hfx-price-reveal-fill *, .hfx-price-reveal-fill::before, .hfx-price-reveal-fill::after, .hfx-price-reveal-fill *::before, .hfx-price-reveal-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.