AI CSS Animations

Gift Box Checkbox

A wrapped present that squashes, swings its lid open on a hinge and lets a gold star float up out of the box. Fun for rewards and streaks. Unchecking drops the star back in and shuts the lid.

Also known as: gift box animation css, reward checkbox, surprise checkbox animation.

HTML

<label class="chk-gift-box">
  <input type="checkbox">
  <span class="chk-gift-box-icon" aria-hidden="true">
    <svg class="chk-gift-box-prize" viewBox="0 0 24 24"><path d="M12 3l2.7 5.6 6.1.9-4.4 4.3 1 6.1L12 17l-5.4 2.9 1-6.1-4.4-4.3 6.1-.9z"/></svg>
    <i class="chk-gift-box-base"></i>
    <i class="chk-gift-box-lid"><b></b><b></b></i>
  </span>
  <span class="chk-gift-box-text">Claim your reward</span>
</label>

CSS

.chk-gift-box {
  --c: var(--chk-color, #3b82f6);
  font-size: var(--chk-size, 24px);
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.6em;
  line-height: 1.3;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  gap: 0.7em;}
.chk-gift-box input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 1;
}
.chk-gift-box-icon {
  position: relative;
  flex: none;
  width: 1.6em;
  height: 1.7em;
  border-radius: 0.3em;
}
.chk-gift-box-prize {
  position: absolute;
  left: 50%;
  top: 55%;
  width: 1em;
  height: 1em;
  margin: -0.5em;
  fill: #fbbf24;
  stroke: #d97706;
  stroke-width: 1.4;
  stroke-linejoin: round;
  transform: translate(0, 0.3em) scale(0.2) rotate(0deg);
  transition: transform 0.25s ease-in;
}
.chk-gift-box-base,
.chk-gift-box-lid {
  position: absolute;
  background: linear-gradient(90deg, transparent 42%, rgb(255 255 255 / 0.8) 42% 58%, transparent 58%), var(--c);
}
.chk-gift-box-base {
  left: 0.12em;
  right: 0.12em;
  bottom: 0;
  height: 0.95em;
  border-radius: 0.1em 0.1em 0.15em 0.15em;
  transform-origin: 50% 100%;
}
.chk-gift-box-lid {
  left: 0;
  right: 0;
  top: 0.42em;
  height: 0.36em;
  border-radius: 0.1em;
  background-color: color-mix(in srgb, var(--c) 80%, #000);
  transform-origin: 0 100%;
  transform: translate(0, 0) rotate(0deg);
  transition: transform 0.3s ease-in 0.1s;
}
.chk-gift-box-lid b {
  position: absolute;
  bottom: 100%;
  left: 50%;
  width: 0.34em;
  height: 0.26em;
  margin-left: -0.33em;
  border: 0.09em solid color-mix(in srgb, var(--c) 80%, #000);
  border-radius: 50%;
  transform: rotate(-25deg);
  transform-origin: 100% 100%;
}
.chk-gift-box-lid b + b {
  margin-left: -0.01em;
  transform: rotate(25deg);
  transform-origin: 0 100%;
}
.chk-gift-box-text {
  transition: color 0.25s ease;
}
.chk-gift-box input:checked + .chk-gift-box-icon .chk-gift-box-base {
  animation: chk-gift-box-squash 0.5s ease-out;
}
.chk-gift-box input:checked + .chk-gift-box-icon .chk-gift-box-lid {
  transform: translate(-0.04em, -0.08em) rotate(-38deg);
  transition: transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) 0.15s;
}
.chk-gift-box input:checked + .chk-gift-box-icon .chk-gift-box-prize {
  transform: translate(0.22em, -0.82em) scale(1) rotate(360deg);
  transition: transform 0.6s cubic-bezier(0.34, 1.4, 0.64, 1) 0.25s;
}
.chk-gift-box input:checked ~ .chk-gift-box-text {
  color: var(--c);
}
.chk-gift-box input:focus-visible + .chk-gift-box-icon {
  outline: 0.12em solid var(--c);
  outline-offset: 0.18em;
}
@keyframes chk-gift-box-squash {
  0% { transform: scale(1, 1); }
  30% { transform: scale(1.08, 0.82); }
  55% { transform: scale(0.97, 1.06); }
  100% { transform: scale(1, 1); }
}

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