AI CSS Animations

Shrink Hover Effect

The opposite of Grow: a raised white button sinks to 94% and its drop shadow tightens, like a card pressed into the page. Suits secondary actions that should feel lighter than the main one.

Also known as: hvr-shrink, scale down on hover css, press in button hover.

HTML

<button class="hfx-shrink"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 4v11M7 10l5 5 5-5M5 20h14"/></svg>Download</button>

CSS

.hfx-shrink {
  --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: 1px solid color-mix(in srgb, var(--c) 25%, transparent);
  background: #fff;
  color: var(--c);
  box-shadow: 0 0.5em 1em -0.35em color-mix(in srgb, var(--c) 55%, 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-shrink svg {
  width: 1.1em;
  height: 1.1em;
}
.hfx-shrink:is(:hover, :focus-visible) {
  transform: scale(0.94);
  box-shadow: 0 0.15em 0.3em -0.1em color-mix(in srgb, var(--c) 45%, transparent);
}

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