Everything travels left to right: the fill wipes in from the left edge and the tick slides in behind it; unchecking wipes it out through the right edge. Swapping transform-origin keeps one direction.
Also known as: slide in checkmark, checkbox wipe animation, left to right checkbox fill.
<label class="chk-sliding-checkmark">
<input type="checkbox">
<span class="chk-sliding-checkmark-box">
<span class="chk-sliding-checkmark-fill"></span>
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5.5 12.5l4 4L18.5 7.5"/></svg>
</span>
Include weekends
</label>.chk-sliding-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-sliding-checkmark input {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
margin: 0;
opacity: 0;
cursor: pointer;
z-index: 1;
}
.chk-sliding-checkmark-box {
position: relative;
box-sizing: border-box;
display: grid;
place-items: center;
flex: none;
width: 1.375em;
height: 1.375em;
overflow: hidden;
border: 0.125em solid color-mix(in srgb, currentColor 38%, transparent);
border-radius: 0.3em;
transition: border-color 0.2s ease 0.15s;
}
.chk-sliding-checkmark-fill {
position: absolute;
inset: 0;
background: var(--c);
transform: scaleX(0);
transform-origin: right;
transition: transform 0.3s cubic-bezier(0.65, 0, 0.35, 1);
}
.chk-sliding-checkmark-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;
opacity: 0;
transform: translateX(-1.1em);
transition: opacity 0.12s ease, transform 0s linear 0.15s;
}
.chk-sliding-checkmark input:checked + .chk-sliding-checkmark-box {
border-color: var(--c);
transition-delay: 0s;
}
.chk-sliding-checkmark input:checked + .chk-sliding-checkmark-box .chk-sliding-checkmark-fill {
transform: scaleX(1);
transform-origin: left;
}
.chk-sliding-checkmark input:checked + .chk-sliding-checkmark-box svg {
opacity: 1;
transform: none;
transition: transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) 0.12s, opacity 0.1s ease 0.12s;
}
.chk-sliding-checkmark input:focus-visible + .chk-sliding-checkmark-box {
outline: 0.125em solid var(--c);
outline-offset: 0.18em;
}
@media (prefers-reduced-motion: reduce) {
.chk-sliding-checkmark, .chk-sliding-checkmark *, .chk-sliding-checkmark::before, .chk-sliding-checkmark::after, .chk-sliding-checkmark *::before, .chk-sliding-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.