AI CSS Animations

Slide Fill Button

An outlined button whose fill slides in from the left on hover while the text flips to white. The fill is a pseudo-element, so the button's own background stays transparent.

Also known as: swipe fill button, background slide hover.

HTML

<button class="hfx-fill-slide">Get started</button>

CSS

.hfx-fill-slide {
  --c: var(--hfx-color, #3b82f6);
  font-size: var(--hfx-size, 16px);
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  padding: 0.7em 1.6em;
  border-radius: 0.5em;
  font: 600 1em system-ui, sans-serif;
  cursor: pointer;
  position: relative;
  isolation: isolate;
  overflow: hidden;
  border: 2px solid var(--c);
  background: transparent;
  color: var(--c);
  transition: color 0.3s ease;}
.hfx-fill-slide::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--c);
  transform: translateX(-101%);
  transition: transform 0.3s ease;
}
.hfx-fill-slide:hover { color: #fff; }
.hfx-fill-slide:hover::before { transform: translateX(0); }

@media (prefers-reduced-motion: reduce) {
  .hfx-fill-slide, .hfx-fill-slide *, .hfx-fill-slide::before, .hfx-fill-slide::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

Customizing this snippet

  • Color: set --hfx-color on the element or a parent. Currently previewing #3b82f6.
  • Base size: set --hfx-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 16px.
  • Speed: change the duration on the transition or animation shorthand. Staggered delays are relative, so they keep their rhythm.
  • Reduced motion: the rule at the end of the CSS turns the motion off for people who asked their OS for less of it. Keep it.

Similar hover effects