How it works
This animated checkbox fills with color when checked and then draws its check mark as if with a pen. It replaces the browser's default checkbox while keeping a real one underneath, so forms, labels and keyboard interaction keep working.
The label holds a hidden native checkbox, a styled box and the text. The box is a rounded square (radius 28% of Box size) with a 2px light border. When the input is checked, :has(:checked) on the label transitions the box background and border to Checked color. The tick is an SVG path with stroke-dasharray: 24 and stroke-dashoffset: 24, which hides the whole stroke; checking moves the offset to 0, so the line appears from its start to its end. The draw has a delay of 40% of Duration, so the box fills first and the mark follows.
Parameters: Label, Box size, Checked color, Check color, Duration and Easing. 18 to 24px suits forms; to-do lists can go larger. Keep Duration between 0.2 and 0.4s: checking things should feel quick.
Clicking the text toggles the box because both are inside the label. The input is still focusable with Tab and toggled with Space. Add a visible :focus-visible style on the box, and check that the unchecked border has at least 3:1 contrast with the background, which WCAG requires for UI components.
How does the check mark draw itself?
The tick is an SVG path. stroke-dasharray: 24 turns the stroke into one dash 24 units long followed by a gap, and stroke-dashoffset: 24 shifts that dash completely out of view. When checked, the offset transitions to 0, which slides the dash into place along the path, so the line appears to be drawn from start to end.
Why is there a delay before the check mark appears?
The tick draws after 40% of Duration has passed, while the box color is already changing. If both happened at once, the dark mark would be drawn on a still-transparent box and briefly be invisible on dark backgrounds. The delay makes the sequence read as fill, then check.
Will the checkbox still submit with my form?
Yes. The native input is still in the markup, only visually hidden, so it submits its name and value like any checkbox. Add name and value attributes to the input in the copied code, and required if needed. Browser validation messages appear on the input as usual.