The box itself becomes the checkmark: two borders fade, the other two stretch into an L, and the whole shape rotates 45 degrees with a spring. Unchecking folds the tick back into a square.
Also known as: checkbox morph animation, box turns into checkmark css, checkbox to tick animation.
<label class="chk-morphing-checkbox"> <input type="checkbox"> <span class="chk-morphing-checkbox-box"></span> Save my preferences </label>
.chk-morphing-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-morphing-checkbox input {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
margin: 0;
opacity: 0;
cursor: pointer;
z-index: 1;
}
.chk-morphing-checkbox-box {
position: relative;
flex: none;
width: 1.25em;
height: 1.25em;
}
.chk-morphing-checkbox-box::before {
content: "";
position: absolute;
left: 0;
top: 0;
box-sizing: border-box;
width: 1.25em;
height: 1.25em;
border: 0.14em solid color-mix(in srgb, currentColor 38%, transparent);
border-radius: 0.22em;
transition:
width 0.3s cubic-bezier(0.5, 0, 0.3, 1),
height 0.3s cubic-bezier(0.5, 0, 0.3, 1),
transform 0.45s cubic-bezier(0.34, 1.4, 0.64, 1),
border-width 0.3s ease,
border-color 0.25s ease,
border-radius 0.25s ease;
}
.chk-morphing-checkbox input:checked + .chk-morphing-checkbox-box::before {
width: 0.6em;
height: 1.3em;
border-width: 0.22em;
border-color: transparent var(--c) var(--c) transparent;
border-radius: 0 0 0.12em 0;
transform: translate(0.325em, -0.26em) rotate(45deg);
}
.chk-morphing-checkbox input:focus-visible + .chk-morphing-checkbox-box {
outline: 0.125em solid var(--c);
outline-offset: 0.18em;
border-radius: 0.22em;
}
@media (prefers-reduced-motion: reduce) {
.chk-morphing-checkbox, .chk-morphing-checkbox *, .chk-morphing-checkbox::before, .chk-morphing-checkbox::after, .chk-morphing-checkbox *::before, .chk-morphing-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.