AI CSS Animations

Inset Shadow Fill Button

The pill's outline is an inset box-shadow, and on hover its spread grows inward from every edge until it fills. No pseudo-elements and no extra markup: one property does it.

Also known as: box shadow fill hover, fill from edges button, no pseudo element fill.

HTML

<button class="hfx-inset-shadow-fill">Subscribe</button>

CSS

.hfx-inset-shadow-fill {
  --c: var(--hfx-color, #3b82f6);
  position: relative;
  isolation: isolate;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  padding: 0.75em 1.75em;
  border-radius: 999em;
  font: 600 var(--hfx-size, 16px)/1.2 system-ui, sans-serif;
  white-space: nowrap;
  cursor: pointer;
  border: 0;
  background: transparent;
  color: var(--c);
  box-shadow: inset 0 0 0 2px var(--c);
  transition: box-shadow 0.45s cubic-bezier(0.65, 0, 0.35, 1), color 0.3s ease 0.12s;
}
.hfx-inset-shadow-fill:is(:hover, :focus-visible) {
  box-shadow: inset 0 0 0 1.5em var(--c);
  color: #fff;
}

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