AI CSS Animations

Staircase Fill Button

Four bars rise one after another and lock together into a solid fill, then drop in reverse order when you leave. The stagger is a --i index per bar feeding transition-delay.

Also known as: staggered bars fill, step fill hover, stair step button.

HTML

<button class="hfx-staircase-fill">
  <span class="hfx-staircase-fill-steps" aria-hidden="true"><i style="--i: 0"></i><i style="--i: 1"></i><i style="--i: 2"></i><i style="--i: 3"></i></span>
  Browse catalog
</button>

CSS

.hfx-staircase-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.25s;
}
.hfx-staircase-fill-steps {
  position: absolute;
  inset: 0;
  z-index: -1;
  display: flex;
}
.hfx-staircase-fill-steps i {
  flex: 1;
  margin-right: -1px;
  background: var(--c);
  transform: translateY(101%);
  transition: transform 0.35s cubic-bezier(0.65, 0, 0.35, 1) calc((3 - var(--i)) * 0.05s);
}
.hfx-staircase-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.25s, background-color 0s 0.6s;
}
.hfx-staircase-fill:is(:hover, :focus-visible) .hfx-staircase-fill-steps i {
  transform: translateY(0);
  transition-delay: calc(var(--i) * 0.07s);
}

@media (prefers-reduced-motion: reduce) {
  .hfx-staircase-fill, .hfx-staircase-fill *, .hfx-staircase-fill::before, .hfx-staircase-fill::after, .hfx-staircase-fill *::before, .hfx-staircase-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 flex" aria-hidden="true">
    <span class="flex-1 translate-y-full bg-blue-500 transition-transform duration-300 ease-in-out group-hover:translate-y-0"></span>
    <span class="flex-1 translate-y-full bg-blue-500 transition-transform duration-300 ease-in-out group-hover:translate-y-0 group-hover:delay-75"></span>
    <span class="flex-1 translate-y-full bg-blue-500 transition-transform duration-300 ease-in-out group-hover:translate-y-0 group-hover:delay-150"></span>
    <span class="flex-1 translate-y-full bg-blue-500 transition-transform duration-300 ease-in-out group-hover:translate-y-0 group-hover:delay-200"></span>
  </span>
  Browse catalog
</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