AI CSS Animations

Animated Checkmark Checkbox

The go-to animated checkbox: the box floods with your accent and an SVG checkmark draws itself with stroke-dashoffset. Unchecking erases the stroke first, then clears the fill.

Also known as: checkmark animation css, css checkbox animation, tick animation css.

HTML

<label class="chk-animated-checkmark">
  <input type="checkbox">
  <span class="chk-animated-checkmark-box">
    <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg>
  </span>
  Remember me
</label>

CSS

.chk-animated-checkmark {
  --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-animated-checkmark input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 1;
}
.chk-animated-checkmark-box {
  box-sizing: border-box;
  display: grid;
  place-items: center;
  flex: none;
  width: 1.25em;
  height: 1.25em;
  border: 0.125em solid color-mix(in srgb, currentColor 38%, transparent);
  border-radius: 0.3em;
  transition: background-color 0.2s ease 0.12s, border-color 0.2s ease 0.12s, transform 0.15s ease;
}
.chk-animated-checkmark-box svg {
  display: block;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  width: 0.85em;
  height: 0.85em;
  stroke: #fff;
  stroke-width: 3;
  stroke-dasharray: 22;
  stroke-dashoffset: 22;
  transition: stroke-dashoffset 0.15s ease-in;
}
.chk-animated-checkmark input:checked + .chk-animated-checkmark-box {
  background: var(--c);
  border-color: var(--c);
  transition-delay: 0s;
}
.chk-animated-checkmark input:checked + .chk-animated-checkmark-box svg {
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.3s cubic-bezier(0.65, 0, 0.35, 1) 0.12s;
}
.chk-animated-checkmark input:active + .chk-animated-checkmark-box {
  transform: scale(0.88);
}
.chk-animated-checkmark input:focus-visible + .chk-animated-checkmark-box {
  outline: 0.125em solid var(--c);
  outline-offset: 0.18em;
}

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

<label class="relative inline-flex cursor-pointer items-center gap-2.5">
  <input type="checkbox" class="peer h-5 w-5 shrink-0 cursor-pointer appearance-none rounded-[5px] border-2 border-gray-400 transition delay-100 duration-200 checked:border-blue-500 checked:bg-blue-500 checked:delay-[0ms] active:scale-90 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500">
  <svg viewBox="0 0 24 24" aria-hidden="true" class="pointer-events-none absolute left-[3px] h-3.5 w-3.5 fill-none stroke-white stroke-[3] transition-[stroke-dashoffset] duration-150 ease-in [stroke-dasharray:22] [stroke-dashoffset:22] [stroke-linecap:round] [stroke-linejoin:round] peer-checked:delay-100 peer-checked:duration-300 peer-checked:[stroke-dashoffset:0]"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg>
  Remember me
</label>

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