The box is a two-sided card: checking flips it over on the Y axis to reveal a filled back face with the tick, overshooting a little as it lands. Uses backface-visibility and perspective().
Also known as: flip checkbox css, flipping checkbox animation, card flip checkbox.
<label class="chk-3d-flip-checkbox">
<input type="checkbox">
<span class="chk-3d-flip-checkbox-card">
<span class="chk-3d-flip-checkbox-front"></span>
<span class="chk-3d-flip-checkbox-back">
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5.5 12.5l4 4L18.5 7.5"/></svg>
</span>
</span>
Public profile
</label>.chk-3d-flip-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;
gap: 0.7em;}
.chk-3d-flip-checkbox input {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
margin: 0;
opacity: 0;
cursor: pointer;
z-index: 1;
}
.chk-3d-flip-checkbox-card {
position: relative;
flex: none;
width: 1.375em;
height: 1.375em;
border-radius: 0.3em;
transform: perspective(4em) rotateY(0deg);
transform-style: preserve-3d;
transition: transform 0.6s cubic-bezier(0.34, 1.35, 0.64, 1);
}
.chk-3d-flip-checkbox-front,
.chk-3d-flip-checkbox-back {
position: absolute;
inset: 0;
box-sizing: border-box;
border-radius: 0.3em;
backface-visibility: hidden;
-webkit-backface-visibility: hidden;
}
.chk-3d-flip-checkbox-front {
border: 0.125em solid color-mix(in srgb, currentColor 38%, transparent);
}
.chk-3d-flip-checkbox-back {
display: grid;
place-items: center;
background: var(--c);
transform: rotateY(180deg);
}
.chk-3d-flip-checkbox-back svg {
display: block;
fill: none;
stroke-linecap: round;
stroke-linejoin: round;
width: 0.9em;
height: 0.9em;
stroke: #fff;
stroke-width: 3.2;
}
.chk-3d-flip-checkbox input:checked + .chk-3d-flip-checkbox-card {
transform: perspective(4em) rotateY(180deg);
}
.chk-3d-flip-checkbox input:focus-visible + .chk-3d-flip-checkbox-card {
outline: 0.125em solid var(--c);
outline-offset: 0.18em;
}
@media (prefers-reduced-motion: reduce) {
.chk-3d-flip-checkbox, .chk-3d-flip-checkbox *, .chk-3d-flip-checkbox::before, .chk-3d-flip-checkbox::after, .chk-3d-flip-checkbox *::before, .chk-3d-flip-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.