AI CSS Animations

Pop Hover Effect

The button pops: it jumps past full size, dips under, then settles, all in half a second. The label pops a beat after the button, which gives the motion a little follow through.

Also known as: hvr-pop, pop out button hover, rubber band hover.

HTML

<button class="hfx-pop"><span class="hfx-pop-label">Try it free</span></button>

CSS

.hfx-pop {
  --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;
  border-radius: 2em;
  background: linear-gradient(135deg, color-mix(in srgb, var(--c) 65%, #fff), var(--c) 60%);
  color: #fff;
  box-shadow: 0 0.4em 1em -0.4em color-mix(in srgb, var(--c) 70%, transparent);}
.hfx-pop-label {
  display: block;
}
.hfx-pop:is(:hover, :focus-visible) {
  animation: hfx-pop-pop 0.5s cubic-bezier(0.25, 0.8, 0.25, 1);
}
.hfx-pop:is(:hover, :focus-visible) .hfx-pop-label {
  animation: hfx-pop-follow 0.5s cubic-bezier(0.25, 0.8, 0.25, 1) 0.08s;
}
@keyframes hfx-pop-pop {
  30% { transform: scale(1.18); }
  55% { transform: scale(0.94); }
  78% { transform: scale(1.04); }
}
/* the label lags a beat and moves less, so it trails the button instead of doubling it */
@keyframes hfx-pop-follow {
  35% { transform: scale(1.06); }
  65% { transform: scale(0.98); }
}

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