AI CSS Animations

Confetti Checkbox

Checking fires a ring of confetti out of the box: eight bits in four colors fly outward, spin and fade while the tick draws. Each bit is a span with an --i index that sets its angle and delay.

Also known as: checkbox particle burst, checkbox burst animation css, celebration checkbox.

HTML

<label class="chk-confetti-checkbox">
  <input type="checkbox">
  <span class="chk-confetti-checkbox-box">
    <span class="chk-confetti-checkbox-bit" style="--i: 0"></span>
    <span class="chk-confetti-checkbox-bit" style="--i: 1"></span>
    <span class="chk-confetti-checkbox-bit" style="--i: 2"></span>
    <span class="chk-confetti-checkbox-bit" style="--i: 3"></span>
    <span class="chk-confetti-checkbox-bit" style="--i: 4"></span>
    <span class="chk-confetti-checkbox-bit" style="--i: 5"></span>
    <span class="chk-confetti-checkbox-bit" style="--i: 6"></span>
    <span class="chk-confetti-checkbox-bit" style="--i: 7"></span>
    <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5.5 12.5l4 4L18.5 7.5"/></svg>
  </span>
  Claim my reward
</label>

CSS

.chk-confetti-checkbox {
  --c: var(--chk-color, #3b82f6);
  font-size: var(--chk-size, 24px);
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.6em;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.3;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.chk-confetti-checkbox input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 1;
}
.chk-confetti-checkbox-box {
  position: relative;
  box-sizing: border-box;
  display: grid;
  place-items: center;
  flex: none;
  width: 1.375em;
  height: 1.375em;
  border: 0.125em solid color-mix(in srgb, currentColor 38%, transparent);
  border-radius: 0.3em;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}
.chk-confetti-checkbox-bit {
  --d: -1.25em;
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0.24em;
  height: 0.24em;
  margin: -0.12em 0 0 -0.12em;
  border-radius: 0.04em;
  background: var(--c);
  opacity: 0;
  pointer-events: none;
}
.chk-confetti-checkbox-bit:nth-child(even) {
  --d: -1.6em;
}
.chk-confetti-checkbox-bit:nth-child(4n + 2) {
  background: #f59e0b;
  border-radius: 50%;
}
.chk-confetti-checkbox-bit:nth-child(4n + 3) {
  background: #ec4899;
}
.chk-confetti-checkbox-bit:nth-child(4n + 4) {
  background: #10b981;
  border-radius: 50%;
}
.chk-confetti-checkbox-box svg {
  display: block;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  position: relative;
  width: 0.9em;
  height: 0.9em;
  stroke: #fff;
  stroke-width: 3.2;
  stroke-dasharray: 20;
  stroke-dashoffset: 20;
  transition: stroke-dashoffset 0.12s ease-in;
}
.chk-confetti-checkbox input:checked + .chk-confetti-checkbox-box {
  background: var(--c);
  border-color: var(--c);
  animation: chk-confetti-checkbox-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.chk-confetti-checkbox input:checked + .chk-confetti-checkbox-box .chk-confetti-checkbox-bit {
  animation: chk-confetti-checkbox-burst 0.75s cubic-bezier(0.15, 0.7, 0.3, 1) calc(var(--i) * 15ms);
}
.chk-confetti-checkbox input:checked + .chk-confetti-checkbox-box svg {
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.3s ease-out 0.15s;
}
.chk-confetti-checkbox input:focus-visible + .chk-confetti-checkbox-box {
  outline: 0.125em solid var(--c);
  outline-offset: 0.18em;
}
@keyframes chk-confetti-checkbox-pop {
  0% { transform: scale(0.8); }
  100% { transform: scale(1); }
}
@keyframes chk-confetti-checkbox-burst {
  0% { opacity: 1; transform: rotate(calc(var(--i) * 45deg)) translateY(-0.4em) scale(0.4) rotate(0deg); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: rotate(calc(var(--i) * 45deg + 20deg)) translateY(var(--d)) scale(1) rotate(180deg); }
}

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

Customizing this snippet

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