AI CSS Animations

Striped Fill Button

Thin diagonal stripes appear and thicken until they merge into a solid fill. The stripe width is a registered @property length, which is what lets a repeating gradient transition.

Also known as: diagonal stripes hover, stripes fill button, hatch fill button.

HTML

<button class="hfx-stripe-fill">Join the beta</button>

CSS

@property --hfx-stripe-fill-w {
  syntax: "<length>";
  inherits: false;
  initial-value: 0px;
}
.hfx-stripe-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.2s;
}
.hfx-stripe-fill::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: repeating-linear-gradient(-45deg, var(--c) 0 var(--hfx-stripe-fill-w), transparent 0 0.9em);
  transition: --hfx-stripe-fill-w 0.5s cubic-bezier(0.65, 0, 0.35, 1);
}
.hfx-stripe-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.2s, background-color 0s 0.5s;
}
.hfx-stripe-fill:is(:hover, :focus-visible)::before { --hfx-stripe-fill-w: 0.9em; }

@media (prefers-reduced-motion: reduce) {
  .hfx-stripe-fill, .hfx-stripe-fill *, .hfx-stripe-fill::before, .hfx-stripe-fill::after, .hfx-stripe-fill *::before, .hfx-stripe-fill *::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