
A moving background can make a call to action feel responsive while its label stays easy to read. This CSS example slides a colored layer behind a link on hover and keyboard focus. The same styling can be applied to a real button when the element performs an action rather than navigating.
Change the CSS below. The preview updates as you type. Your edits stay in this browser tab.
Hover or Tab to the link. Change --fill and the transition duration.
HTML for this example
<div class="button-stage"><a class="slide-button" href="#button-result"><span>Explore the project</span><span aria-hidden="true">↗</span></a><p id="button-result" class="example-note">Demo destination. Use a link for navigation and a button for an action.</p></div>
Move a separate paint layer
The ::before pseudo-element fills the link with inset: 0. It starts just outside the left edge with translateX(-101%). Hover or focus brings it back to zero. overflow: hidden clips it to the rounded outline, while isolation: isolate keeps its negative stacking level within this component.
Try a different direction
Change the starting transform to translateY(101%) and the active transform to translateY(0) for a fill that rises from below. Adjust the duration before adding more effects. The text does not need to move or change color; choose a fill that keeps it readable in both states.
Check more than the hover state
Tab to the link and make sure the focus outline stays visible outside its border. Reduced-motion preferences remove the transition while retaining the final color change. Keep a comfortable target size and test longer labels on phones. If you copy the styling onto a button, set its type intentionally so it does not accidentally submit a form.
Reference: MDN on stacking isolation.
Have a client website that needs this kind of attention? See our WordPress development for agencies and case studies.


Great tutorial! I like how you explained the sliding background effect with a focus on accessibility, keyboard navigation, and reduced-motion preferences. The live CSS preview is also a useful way to experiment with different effects and transition speeds. These small details can make buttons more engaging while keeping the user experience smooth and accessible. Thanks for sharing!