A parent row whose box mirrors its children: empty, a dash when some are checked, a check when all are. The dash folds away as the check draws in. Pure CSS: the parent reads them with :has().
Also known as: indeterminate checkbox css, select all checkbox css, tri-state checkbox.
<div class="chk-indeterminate-checkbox-group" role="group" aria-labelledby="chk-indeterminate-checkbox-group-title">
<div class="chk-indeterminate-checkbox-group-head">
<span class="chk-indeterminate-checkbox-group-box chk-indeterminate-checkbox-group-parent" aria-hidden="true"><i class="chk-indeterminate-checkbox-group-dash"></i><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg></span>
<span id="chk-indeterminate-checkbox-group-title">Toppings</span>
</div>
<div class="chk-indeterminate-checkbox-group-kids">
<label class="chk-indeterminate-checkbox-group-item"><input type="checkbox" checked><span class="chk-indeterminate-checkbox-group-box"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg></span>Cheese</label>
<label class="chk-indeterminate-checkbox-group-item"><input type="checkbox"><span class="chk-indeterminate-checkbox-group-box"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg></span>Basil</label>
<label class="chk-indeterminate-checkbox-group-item"><input type="checkbox"><span class="chk-indeterminate-checkbox-group-box"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg></span>Olives</label>
</div>
</div>.chk-indeterminate-checkbox-group {
--c: var(--chk-color, #3b82f6);
font-size: var(--chk-size, 24px);
display: grid;
gap: 0.3em;
line-height: 1.3;}
.chk-indeterminate-checkbox-group-head {
display: flex;
align-items: center;
gap: 0.55em;
font-weight: 600;
}
.chk-indeterminate-checkbox-group-kids {
display: grid;
gap: 0.2em;
margin-left: 0.55em;
padding-left: 1em;
border-left: 0.08em solid color-mix(in srgb, currentColor 18%, transparent);
}
.chk-indeterminate-checkbox-group-item {
position: relative;
display: flex;
align-items: center;
gap: 0.55em;
font-size: 0.9em;
cursor: pointer;
-webkit-user-select: none;
user-select: none;
}
.chk-indeterminate-checkbox-group-item input {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
margin: 0;
opacity: 0;
cursor: pointer;
z-index: 1;
}
.chk-indeterminate-checkbox-group-box {
position: relative;
display: grid;
place-items: center;
flex: none;
width: 1.1em;
height: 1.1em;
border: 0.12em solid color-mix(in srgb, currentColor 38%, transparent);
border-radius: 0.3em;
transition: background-color 0.2s ease, border-color 0.2s ease;
}
.chk-indeterminate-checkbox-group-box svg {
grid-area: 1 / 1;
width: 0.82em;
height: 0.82em;
fill: none;
stroke: #fff;
stroke-width: 3.6;
stroke-linecap: round;
stroke-linejoin: round;
stroke-dasharray: 20;
stroke-dashoffset: 20;
transition: stroke-dashoffset 0.2s ease-in;
}
.chk-indeterminate-checkbox-group-dash {
grid-area: 1 / 1;
width: 0.55em;
height: 0.13em;
border-radius: 1em;
background: #fff;
transform: scaleX(0);
transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.chk-indeterminate-checkbox-group-item input:checked + .chk-indeterminate-checkbox-group-box,
.chk-indeterminate-checkbox-group:has(input:checked) .chk-indeterminate-checkbox-group-parent {
background: var(--c);
border-color: var(--c);
}
.chk-indeterminate-checkbox-group-item input:checked + .chk-indeterminate-checkbox-group-box svg {
stroke-dashoffset: 0;
transition: stroke-dashoffset 0.3s ease-out 0.05s;
}
.chk-indeterminate-checkbox-group:has(input:checked) .chk-indeterminate-checkbox-group-dash {
transform: scaleX(1);
}
.chk-indeterminate-checkbox-group:not(:has(input:not(:checked))) .chk-indeterminate-checkbox-group-dash {
transform: scaleX(0);
transition-duration: 0.15s;
}
.chk-indeterminate-checkbox-group:not(:has(input:not(:checked))) .chk-indeterminate-checkbox-group-parent svg {
stroke-dashoffset: 0;
transition: stroke-dashoffset 0.3s ease-out 0.12s;
}
.chk-indeterminate-checkbox-group-item input:focus-visible + .chk-indeterminate-checkbox-group-box {
outline: 0.12em solid var(--c);
outline-offset: 0.18em;
}
@media (prefers-reduced-motion: reduce) {
.chk-indeterminate-checkbox-group, .chk-indeterminate-checkbox-group *, .chk-indeterminate-checkbox-group::before, .chk-indeterminate-checkbox-group::after, .chk-indeterminate-checkbox-group *::before, .chk-indeterminate-checkbox-group *::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.