Checkbox
A checkbox with a drawn tick, an indeterminate parent and a select-all pattern.
AI prompt
Build a checkbox group with a parent "Select all" and three children (Email, SMS, Push). Each checkbox is a real input type="checkbox" hidden visually, with a custom 22px box (6px radius, 1.5px border) and an SVG tick drawn with stroke-dasharray 24. When checked the box fills with the accent colour and the tick animates stroke-dashoffset from 24 to 0 over 220ms ease-out. The parent shows an indeterminate dash (set input.indeterminate = true) when only some children are checked, and checking the parent checks or clears all children. Rows are at least 44px tall and the whole label is clickable. Include hover tone, a 2px focus-visible ring and a disabled child. Under prefers-reduced-motion show the tick without animation.About this pattern
Definition
A square control that lets a person choose zero or more options from a set. The tick draws itself on check. A parent checkbox can show an indeterminate state when only some children are checked.
Purpose & UX principles
- Use checkboxes for independent choices that are confirmed later; use a switch for settings that apply instantly.
- Indeterminate shows partial selection and lets one control select or clear the whole group.
- The clickable area includes the label text, not just the 20px box.
Interaction states
- Unchecked, checked, indeterminate, hover, focus-visible, disabled.
- Parent checkbox reflects the children and toggles them all when activated.
Motion specification
- Box fill: 140ms.
- Tick: stroke-dashoffset from 24 to 0 in 220ms ease-out.
- Reduced motion: tick appears without drawing.
Responsive behaviour
- Visual box 22px inside a row at least 44px tall so the whole row is a comfortable touch target.
Code
<fieldset class="g"><legend>Notify me by</legend>
<label class="c"><input type="checkbox" id="all"><i><svg viewBox="0 0 24 24"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg></i><span>Select all</span></label>
<label class="c"><input type="checkbox" class="ch" checked><i><svg viewBox="0 0 24 24"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg></i><span>Email</span></label>
<label class="c"><input type="checkbox" class="ch"><i><svg viewBox="0 0 24 24"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg></i><span>SMS</span></label>
<label class="c"><input type="checkbox" class="ch"><i><svg viewBox="0 0 24 24"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg></i><span>Push</span></label>
<label class="c off"><input type="checkbox" disabled><i><svg viewBox="0 0 24 24"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg></i><span>Carrier pigeon</span></label>
</fieldset>:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
.g{width:min(300px,100%);border:1px solid var(--line);border-radius:18px;background:var(--surface);padding:10px 14px 8px}
legend{padding:0 8px;color:var(--muted);font-size:12px;letter-spacing:.12em;text-transform:uppercase}
.c{display:flex;align-items:center;gap:12px;min-height:44px;cursor:pointer;position:relative}
.c input{position:absolute;opacity:0;width:1px;height:1px}
.c i{flex:none;display:grid;place-items:center;width:22px;height:22px;border-radius:6px;border:1.5px solid var(--muted);transition:background .14s,border-color .14s}
.c svg{width:18px;height:18px;fill:none;stroke:var(--accent-ink);stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:24;stroke-dashoffset:24}
.c input:checked+i,.c input:indeterminate+i{background:var(--accent);border-color:var(--accent)}
.c input:checked+i svg{stroke-dashoffset:0;transition:stroke-dashoffset .22s ease-out}
.c input:indeterminate+i svg{display:none}
.c input:indeterminate+i::after{content:"";width:10px;height:2.5px;border-radius:2px;background:var(--accent-ink)}
.c:hover i{border-color:var(--text)}
.c input:focus-visible+i{outline:2px solid var(--accent);outline-offset:3px}
.off{opacity:.4;cursor:not-allowed}
@media (prefers-reduced-motion:reduce){.c i,.c input:checked+i svg{transition:none}}const all=document.getElementById('all'),ch=[...document.querySelectorAll('.ch')];
function sync(){const n=ch.filter(c=>c.checked).length;all.checked=n===ch.length;all.indeterminate=n>0&&n<ch.length;}
all.addEventListener('change',()=>{ch.forEach(c=>c.checked=all.checked);all.indeterminate=false;});
ch.forEach(c=>c.addEventListener('change',sync));sync();One complete HTML file. Save it and open it in a browser.
<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Checkbox — demo</title>
<style>
:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
html,body{height:100%}body{background:var(--bg);color:var(--text);font:15px/1.5 -apple-system,BlinkMacSystemFont,'Segoe UI',Inter,Roboto,sans-serif;-webkit-font-smoothing:antialiased}.stage{min-height:100%;display:grid;place-items:center;padding:24px}button,input,select,textarea{font-family:inherit}@media (prefers-reduced-motion:reduce){html{scroll-behavior:auto}}
.g{width:min(300px,100%);border:1px solid var(--line);border-radius:18px;background:var(--surface);padding:10px 14px 8px}
legend{padding:0 8px;color:var(--muted);font-size:12px;letter-spacing:.12em;text-transform:uppercase}
.c{display:flex;align-items:center;gap:12px;min-height:44px;cursor:pointer;position:relative}
.c input{position:absolute;opacity:0;width:1px;height:1px}
.c i{flex:none;display:grid;place-items:center;width:22px;height:22px;border-radius:6px;border:1.5px solid var(--muted);transition:background .14s,border-color .14s}
.c svg{width:18px;height:18px;fill:none;stroke:var(--accent-ink);stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:24;stroke-dashoffset:24}
.c input:checked+i,.c input:indeterminate+i{background:var(--accent);border-color:var(--accent)}
.c input:checked+i svg{stroke-dashoffset:0;transition:stroke-dashoffset .22s ease-out}
.c input:indeterminate+i svg{display:none}
.c input:indeterminate+i::after{content:"";width:10px;height:2.5px;border-radius:2px;background:var(--accent-ink)}
.c:hover i{border-color:var(--text)}
.c input:focus-visible+i{outline:2px solid var(--accent);outline-offset:3px}
.off{opacity:.4;cursor:not-allowed}
@media (prefers-reduced-motion:reduce){.c i,.c input:checked+i svg{transition:none}}
</style></head>
<body><div class="stage">
<fieldset class="g"><legend>Notify me by</legend>
<label class="c"><input type="checkbox" id="all"><i><svg viewBox="0 0 24 24"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg></i><span>Select all</span></label>
<label class="c"><input type="checkbox" class="ch" checked><i><svg viewBox="0 0 24 24"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg></i><span>Email</span></label>
<label class="c"><input type="checkbox" class="ch"><i><svg viewBox="0 0 24 24"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg></i><span>SMS</span></label>
<label class="c"><input type="checkbox" class="ch"><i><svg viewBox="0 0 24 24"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg></i><span>Push</span></label>
<label class="c off"><input type="checkbox" disabled><i><svg viewBox="0 0 24 24"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg></i><span>Carrier pigeon</span></label>
</fieldset>
</div>
<script>
const all=document.getElementById('all'),ch=[...document.querySelectorAll('.ch')];
function sync(){const n=ch.filter(c=>c.checked).length;all.checked=n===ch.length;all.indeterminate=n>0&&n<ch.length;}
all.addEventListener('change',()=>{ch.forEach(c=>c.checked=all.checked);all.indeterminate=false;});
ch.forEach(c=>c.addEventListener('change',sync));sync();
</script>
</body></html>