AI CSS Animations

Confetti Burst Button

A celebratory button that pops a ring of confetti from behind itself when hovered: dots and strips fly out, spin, drift down and fade. Ten plain elements, each with its own vector.

Also known as: confetti button css, party popper hover, particle burst button.

HTML

<button class="btn-confetti-burst">
  <span class="btn-confetti-burst-bits" aria-hidden="true">
    <i style="--x:6.2em;--y:-0.3em"></i><i style="--x:4.8em;--y:1.8em"></i><i style="--x:2em;--y:2.6em"></i><i style="--x:-1.6em;--y:2.9em"></i><i style="--x:-4.9em;--y:1.6em"></i><i style="--x:-6.4em;--y:0.2em"></i><i style="--x:-5em;--y:-1.7em"></i><i style="--x:-2.2em;--y:-2.7em"></i><i style="--x:1.4em;--y:-3em"></i><i style="--x:4.6em;--y:-2em"></i>
  </span>
  <span class="btn-confetti-burst-face">Celebrate</span>
</button>

CSS

.btn-confetti-burst {
  --c: var(--btn-color, #3b82f6);
  position: relative;
  padding: 0;
  border: 0;
  background: transparent;
  font: 600 var(--btn-size, 18px)/1.2 system-ui, sans-serif;
  cursor: pointer;
}
.btn-confetti-burst-face {
  position: relative;
  display: block;
  padding: 0.8em 1.9em;
  border-radius: 0.6em;
  background: var(--c);
  color: #fff;
}
.btn-confetti-burst-bits i {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0.45em;
  height: 0.45em;
  margin: -0.225em;
  border-radius: 50%;
  background: var(--c);
  opacity: 0;
}
.btn-confetti-burst-bits i:nth-child(3n + 2) {
  width: 0.3em;
  height: 0.6em;
  border-radius: 0.08em;
  background: color-mix(in srgb, var(--c) 30%, #f43f5e);
}
.btn-confetti-burst-bits i:nth-child(3n) { background: color-mix(in srgb, var(--c) 20%, #fbbf24); }
.btn-confetti-burst:is(:hover, :focus-visible) .btn-confetti-burst-face {
  animation: btn-confetti-burst-pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.btn-confetti-burst:is(:hover, :focus-visible) .btn-confetti-burst-bits i {
  animation: btn-confetti-burst-fly 1s cubic-bezier(0.2, 0.7, 0.3, 1) both;
}
.btn-confetti-burst:is(:hover, :focus-visible) .btn-confetti-burst-bits i:nth-child(even) { animation-delay: 0.05s; }
@keyframes btn-confetti-burst-fly {
  0%   { opacity: 1; transform: translate(0, 0) scale(0.4) rotate(0deg); }
  65%  { opacity: 1; transform: translate(var(--x), var(--y)) scale(1) rotate(200deg); }
  100% { opacity: 0; transform: translate(var(--x), calc(var(--y) + 0.9em)) scale(0.8) rotate(280deg); }
}
@keyframes btn-confetti-burst-pop {
  40% { transform: scale(0.93); }
}

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

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