AI CSS Animations

Bouncing Button

A button that hops on its own every couple of seconds: it squashes to wind up, jumps, stretches, lands with a squash and settles, while its shadow shrinks and grows on the ground below.

Also known as: css button bounce animation, jumping button css, bounce attention button.

HTML

<button class="btn-bounce" type="button"><span class="btn-bounce-face">Claim reward</span></button>

CSS

.btn-bounce {
  --c: var(--btn-color, #3b82f6);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  padding: 0.75em 1.6em;
  border: 0;
  border-radius: 0.6em;
  font: 600 var(--btn-size, 18px)/1.1 system-ui, sans-serif;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  padding: 0 0 0.8em;
  background: transparent;
  color: #fff;}
.btn-bounce::after {
  content: "";
  position: absolute;
  right: 12%;
  bottom: 0;
  left: 12%;
  height: 0.55em;
  border-radius: 50%;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--c) 55%, transparent), transparent);
  animation: btn-bounce-shadow 2.2s infinite;
}
.btn-bounce-face {
  display: block;
  padding: 0.8em 1.8em;
  border-radius: 0.75em;
  background: var(--c);
  transform-origin: 50% 100%;
  animation: btn-bounce-hop 2.2s infinite;
}
.btn-bounce:active .btn-bounce-face { animation-play-state: paused; }
@keyframes btn-bounce-hop {
  0%   { transform: translateY(0) scale(1, 1); animation-timing-function: ease-out; }
  8%   { transform: translateY(0) scale(1.1, 0.88); animation-timing-function: cubic-bezier(0.2, 0.8, 0.4, 1); }
  30%  { transform: translateY(-1.5em) scale(0.95, 1.06); animation-timing-function: cubic-bezier(0.5, 0, 0.8, 0.4); }
  46%  { transform: translateY(0) scale(1.12, 0.86); animation-timing-function: ease-out; }
  56%  { transform: translateY(-0.35em) scale(0.98, 1.03); animation-timing-function: ease-in; }
  64%  { transform: translateY(0) scale(1.04, 0.96); animation-timing-function: ease-out; }
  72%, 100% { transform: translateY(0) scale(1, 1); }
}
@keyframes btn-bounce-shadow {
  0%, 8%, 46%, 64%, 72%, 100% { transform: scale(1); opacity: 1; }
  30% { transform: scale(0.6); opacity: 0.45; }
  56% { transform: scale(0.9); opacity: 0.85; }
}

@media (prefers-reduced-motion: reduce) {
  .btn-bounce, .btn-bounce *, .btn-bounce::before, .btn-bounce::after, .btn-bounce *::before, .btn-bounce *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

Tailwind CSS version

The same effect using Tailwind utility classes. No custom CSS or config needed.

<button class="animate-bounce rounded-xl bg-blue-500 px-7 py-3 font-semibold text-white shadow-lg shadow-blue-500/30">
  Claim reward
</button>

Customizing this snippet

  • Color: set --btn-color on the element or a parent. Currently previewing #3b82f6.
  • Base size: set --btn-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 18px.
  • 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 buttons