How it works
The fill sweep button is an outline button that fills with color from the left side on hover, and its label switches color at the same time so it stays readable on the new background. It is one of the most requested button hover effects in CSS because it makes a quiet secondary button feel like a primary one under the pointer.
The outline is an inset box-shadow 2px wide in Fill color. Behind the label sits a fill element covering the whole button, with z-index: -1, transform-origin: left and transform: scaleX(0). On hover it transitions to scaleX(1). The button has isolation: isolate, which creates a stacking context so that z-index: -1 places the fill behind the label but still inside the button, rather than behind the page. The label transitions its color from Text color to Hover text color over the same duration.
Parameters: Label, Fill color, Text color, Hover text color, Corner radius, Duration and Easing. Pick Hover text color to contrast with Fill color, not with the page background. The default expo-out at 0.4s makes the fill race across and settle softly.
Only transform and color change, so it is cheap even in long button rows. Add :focus-visible to the hover selectors so keyboard focus produces the same fill, and consider @media (hover: hover) to avoid a sticky filled state after taps on phones.
How do I make the fill come from the top or the right?
Change transform-origin and the scale axis on the fill element. For a fill from the right use transform-origin: right with scaleX. For a fill from the bottom use transform-origin: bottom and swap scaleX(0) and scaleX(1) for scaleY(0) and scaleY(1). The label color transition stays the same.
Why does the button need isolation: isolate?
The fill has z-index: -1 so it can sit behind the label. Without a stacking context on the button, that negative z-index would push the fill behind the button's parent background, and you would never see it. isolation: isolate creates the stacking context without side effects like the ones position plus z-index or a transform would have.
Can I keep the outline visible after the fill?
The outline is an inset box-shadow in the same color as the fill, so it blends in once the button is full. If you want a visible edge in the hovered state, set a different shadow color in a hover rule, for example a darker shade of the fill, or draw the outline in Hover text color.