AI CSS Animations

Scribble Fill Button

A marker zigzags across the button and colors it in like a margin doodle, then the ink settles solid. One inline SVG path drawn with stroke-dashoffset; pathLength=1 keeps the math simple.

Also known as: marker fill button, hand drawn fill hover, crayon scribble button.

HTML

<button class="hfx-scribble-fill"><svg class="hfx-scribble-fill-svg" viewBox="0 0 100 28" preserveAspectRatio="xMidYMid slice" aria-hidden="true"><path pathLength="1" d="M-8 30 L8 -3 L4 31 L20 -5 L16 33 L32 -2 L28 30 L44 -4 L40 32 L56 -3 L52 31 L68 -5 L64 33 L80 -2 L76 30 L92 -4 L88 32 L104 -3 L100 31 L116 -5 L112 33"/></svg>Sign the petition</button>

CSS

.hfx-scribble-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.2s ease, background-color 0.15s ease;
}
.hfx-scribble-fill-svg {
  position: absolute;
  inset: 0;
  z-index: -1;
  width: 100%;
  height: 100%;
  fill: none;
  stroke: var(--c);
  stroke-width: 6.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1 1.1;
  stroke-dashoffset: 1.02;
  transition: stroke-dashoffset 0.4s cubic-bezier(0.5, 0, 0.75, 0);
}
/* once the scribble is done, the button's own background fills the gaps */
.hfx-scribble-fill:is(:hover, :focus-visible) {
  background-color: var(--c);
  color: #fff;
  transition: color 0.2s ease 0.45s, background-color 0.25s ease 0.6s;
}
.hfx-scribble-fill:is(:hover, :focus-visible) .hfx-scribble-fill-svg {
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.7s cubic-bezier(0.45, 0, 0.3, 1);
}

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