A flat line grows out of the center of the box, then bends at a hinge into a tick with a spring. Unchecking flattens the tick back into a line and shrinks it away. Two bars, only transforms.
Also known as: checkmark morph animation css, line to tick animation, bending checkmark.
<label class="chk-line-to-checkmark">
<input type="checkbox">
<span class="chk-line-to-checkmark-box">
<span class="chk-line-to-checkmark-short"></span>
<span class="chk-line-to-checkmark-long"></span>
</span>
Approve changes
</label>.chk-line-to-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-line-to-checkmark input {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
margin: 0;
opacity: 0;
cursor: pointer;
z-index: 1;
}
.chk-line-to-checkmark-box {
position: relative;
box-sizing: border-box;
flex: none;
width: 1.3em;
height: 1.3em;
border: 0.125em solid color-mix(in srgb, currentColor 38%, transparent);
border-radius: 0.3em;
transition: background-color 0.2s ease, border-color 0.2s ease;
}
.chk-line-to-checkmark-short,
.chk-line-to-checkmark-long {
position: absolute;
left: -0.07em;
top: -0.07em;
height: 0.14em;
border-radius: 0.07em;
background: #fff;
transform-origin: 0.07em 50%;
transition: transform 0.2s ease-in;
}
.chk-line-to-checkmark-short {
width: 0.465em;
transform: translate(0.525em, 0.525em) rotate(180deg) scaleX(0);
}
.chk-line-to-checkmark-long {
width: 0.777em;
transform: translate(0.525em, 0.525em) rotate(0deg) scaleX(0);
}
.chk-line-to-checkmark input:checked + .chk-line-to-checkmark-box {
background: var(--c);
border-color: var(--c);
}
.chk-line-to-checkmark input:checked + .chk-line-to-checkmark-box .chk-line-to-checkmark-short {
transform: translate(0.43em, 0.75em) rotate(225deg) scaleX(1);
animation: chk-line-to-checkmark-short 0.55s;
}
.chk-line-to-checkmark input:checked + .chk-line-to-checkmark-box .chk-line-to-checkmark-long {
transform: translate(0.43em, 0.75em) rotate(-47.5deg) scaleX(1);
animation: chk-line-to-checkmark-long 0.55s;
}
.chk-line-to-checkmark input:focus-visible + .chk-line-to-checkmark-box {
outline: 0.125em solid var(--c);
outline-offset: 0.18em;
}
@keyframes chk-line-to-checkmark-short {
0% { transform: translate(0.525em, 0.525em) rotate(180deg) scaleX(0); animation-timing-function: cubic-bezier(0.2, 0, 0.2, 1); }
38% { transform: translate(0.525em, 0.525em) rotate(180deg) scaleX(0.88); animation-timing-function: cubic-bezier(0.34, 1.56, 0.64, 1); }
100% { transform: translate(0.43em, 0.75em) rotate(225deg) scaleX(1); }
}
@keyframes chk-line-to-checkmark-long {
0% { transform: translate(0.525em, 0.525em) rotate(0deg) scaleX(0); animation-timing-function: cubic-bezier(0.2, 0, 0.2, 1); }
38% { transform: translate(0.525em, 0.525em) rotate(0deg) scaleX(0.53); animation-timing-function: cubic-bezier(0.34, 1.56, 0.64, 1); }
100% { transform: translate(0.43em, 0.75em) rotate(-47.5deg) scaleX(1); }
}
@media (prefers-reduced-motion: reduce) {
.chk-line-to-checkmark, .chk-line-to-checkmark *, .chk-line-to-checkmark::before, .chk-line-to-checkmark::after, .chk-line-to-checkmark *::before, .chk-line-to-checkmark *::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.