AI CSS Animations

Double Layer Fill Button

A pale tint sweeps across first and the solid color chases it a beat later, then they leave in reverse order. Two pseudo-elements, one easing curve, different delays.

Also known as: two tone fill hover, staggered fill button, layered sweep.

HTML

<button class="hfx-double-layer-fill">Explore plans</button>

CSS

.hfx-double-layer-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);
  transition: color 0.25s ease 0.3s;
}
.hfx-double-layer-fill::before,
.hfx-double-layer-fill::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  transform: translateX(-101%);
  transition: transform 0.45s cubic-bezier(0.7, 0, 0.2, 1);
}
.hfx-double-layer-fill::before {
  background: color-mix(in srgb, var(--c) 40%, #fff);
  transition-delay: 0.1s;
}
.hfx-double-layer-fill::after { background: var(--c); }
.hfx-double-layer-fill:is(:hover, :focus-visible) {
  background-color: var(--c); /* hides the hairline where the fill meets the border */
  color: #fff;
  transition: color 0.25s ease 0.3s, background-color 0s 0.6s;
}
.hfx-double-layer-fill:is(:hover, :focus-visible)::before,
.hfx-double-layer-fill:is(:hover, :focus-visible)::after {
  transform: translateX(0);
}
.hfx-double-layer-fill:is(:hover, :focus-visible)::before { transition-delay: 0s; }
.hfx-double-layer-fill:is(:hover, :focus-visible)::after { transition-delay: 0.12s; }

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

Tailwind CSS version

The same effect using Tailwind utility classes. No custom CSS or config needed.

<button class="group relative isolate overflow-hidden rounded-lg border-2 border-blue-500 px-7 py-3 font-semibold text-blue-500 transition-colors delay-150 duration-300 hover:text-white">
  <span class="absolute inset-0 -z-10 -translate-x-full bg-blue-200 transition-transform delay-100 duration-500 ease-in-out group-hover:translate-x-0 group-hover:delay-0"></span>
  <span class="absolute inset-0 -z-10 -translate-x-full bg-blue-500 transition-transform duration-500 ease-in-out group-hover:translate-x-0 group-hover:delay-100"></span>
  Explore plans
</button>

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