AI CSS Animations

Bounce Checkbox

Checking squashes the box flat, stretches it tall and lets it settle, like a ball landing, while the tick springs out from the middle. Squash and stretch keyframes, anchored at the bottom edge.

Also known as: bouncy checkbox css, checkbox bounce animation, squash and stretch checkbox.

HTML

<label class="chk-bounce-checkbox">
  <input type="checkbox">
  <span class="chk-bounce-checkbox-box">
    <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5.5 12.5l4 4L18.5 7.5"/></svg>
  </span>
  Join the waitlist
</label>

CSS

.chk-bounce-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-bounce-checkbox input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 1;
}
.chk-bounce-checkbox-box {
  box-sizing: border-box;
  display: grid;
  place-items: center;
  flex: none;
  width: 1.3em;
  height: 1.3em;
  border: 0.125em solid color-mix(in srgb, currentColor 38%, transparent);
  border-radius: 0.32em;
  transform-origin: 50% 100%;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}
.chk-bounce-checkbox-box svg {
  display: block;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  width: 0.85em;
  height: 0.85em;
  stroke: #fff;
  stroke-width: 3.2;
  transform: scale(0);
  transition: transform 0.15s ease-in;
}
.chk-bounce-checkbox input:checked + .chk-bounce-checkbox-box {
  background: var(--c);
  border-color: var(--c);
  animation: chk-bounce-checkbox-squash 0.6s cubic-bezier(0.3, 0.1, 0.3, 1);
}
.chk-bounce-checkbox input:checked + .chk-bounce-checkbox-box svg {
  transform: scale(1);
  transition: transform 0.45s cubic-bezier(0.34, 1.8, 0.64, 1) 0.15s;
}
.chk-bounce-checkbox input:focus-visible + .chk-bounce-checkbox-box {
  outline: 0.125em solid var(--c);
  outline-offset: 0.18em;
}
@keyframes chk-bounce-checkbox-squash {
  0%, 100% { transform: scale(1, 1); }
  18% { transform: scale(1.28, 0.72); }
  38% { transform: scale(0.82, 1.2); }
  58% { transform: scale(1.1, 0.92); }
  78% { transform: scale(0.97, 1.03); }
}

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