The box makes a half turn as it fills, overshooting before it squares up, and the tick spins in upright once it lands. Unchecking unwinds it. The box is a pseudo-element, so the label stays put.
Also known as: rotating checkbox css, spin checkbox animation.
<label class="chk-spin-checkbox">
<input type="checkbox">
<span class="chk-spin-checkbox-box">
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5.5 12.5l4 4L18.5 7.5"/></svg>
</span>
Auto-renew
</label>.chk-spin-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-spin-checkbox input {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
margin: 0;
opacity: 0;
cursor: pointer;
z-index: 1;
}
.chk-spin-checkbox-box {
position: relative;
display: grid;
place-items: center;
flex: none;
width: 1.375em;
height: 1.375em;
border-radius: 0.3em;
}
.chk-spin-checkbox-box::before {
content: "";
position: absolute;
inset: 0;
box-sizing: border-box;
border: 0.125em solid color-mix(in srgb, currentColor 38%, transparent);
border-radius: 0.3em;
transition: transform 0.5s cubic-bezier(0.34, 1.3, 0.64, 1), background-color 0.25s ease, border-color 0.25s ease;
}
.chk-spin-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;
transform: rotate(-120deg) scale(0);
transition: transform 0.15s ease-in;
}
.chk-spin-checkbox input:checked + .chk-spin-checkbox-box::before {
background: var(--c);
border-color: var(--c);
transform: rotate(180deg);
}
.chk-spin-checkbox input:checked + .chk-spin-checkbox-box svg {
transform: rotate(0deg) scale(1);
transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) 0.22s;
}
.chk-spin-checkbox input:focus-visible + .chk-spin-checkbox-box {
outline: 0.125em solid var(--c);
outline-offset: 0.18em;
}
@media (prefers-reduced-motion: reduce) {
.chk-spin-checkbox, .chk-spin-checkbox *, .chk-spin-checkbox::before, .chk-spin-checkbox::after, .chk-spin-checkbox *::before, .chk-spin-checkbox *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}--chk-color on the element or a parent.
Currently previewing #3b82f6.--chk-size. Every other dimension is in
em, so the whole thing scales together. Currently previewing 24px.transition or animation
shorthand. Staggered delays are relative, so they keep their rhythm.