AI CSS Animations

Box Shadow Outset Hover Effect

The button steps up and to the left while three hard shadows fan out behind it in fading tints, like a stack of cards. One box-shadow list transitions from three zero offsets to three growing ones.

Also known as: hvr-box-shadow-outset, stacked box shadow hover, layered shadow button css.

HTML

<button class="hfx-box-shadow-outset">Start building</button>

CSS

.hfx-box-shadow-outset {
  --c: var(--hfx-color, #3b82f6);
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  padding: 0.7em 1.6em;
  border-radius: 0.5em;
  font: 600 var(--hfx-size, 16px) system-ui, sans-serif;
  cursor: pointer;
  border: 0;
  background: var(--c);
  color: #fff;
  border-radius: 0.35em;
  box-shadow: 0 0 0 color-mix(in srgb, var(--c) 60%, transparent), 0 0 0 color-mix(in srgb, var(--c) 35%, transparent), 0 0 0 color-mix(in srgb, var(--c) 18%, transparent);
  transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1), box-shadow 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);}
.hfx-box-shadow-outset:is(:hover, :focus-visible) {
  transform: translate(-0.3em, -0.3em);
  box-shadow: 0.25em 0.25em 0 color-mix(in srgb, var(--c) 60%, transparent), 0.5em 0.5em 0 color-mix(in srgb, var(--c) 35%, transparent), 0.75em 0.75em 0 color-mix(in srgb, var(--c) 18%, transparent);
}

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