A to-do item that ticks its box, then draws a line through the task from left to right and dims it. Unchecking wipes the line away. The strike is one scaled ::after, so it fits any text length.
Also known as: todo list checkbox css, strikethrough checkbox css, line through checked text.
<label class="chk-todo-strikethrough"> <input type="checkbox"> <span class="chk-todo-strikethrough-box"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg></span> <span class="chk-todo-strikethrough-text">Call the dentist</span> </label>
.chk-todo-strikethrough {
--c: var(--chk-color, #3b82f6);
font-size: var(--chk-size, 24px);
position: relative;
display: inline-flex;
align-items: center;
gap: 0.6em;
line-height: 1.3;
cursor: pointer;
-webkit-user-select: none;
user-select: none;
-webkit-tap-highlight-color: transparent;
}
.chk-todo-strikethrough input {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
margin: 0;
opacity: 0;
cursor: pointer;
z-index: 1;
}
.chk-todo-strikethrough-box {
display: grid;
place-items: center;
flex: none;
width: 1.2em;
height: 1.2em;
border: 0.12em solid color-mix(in srgb, currentColor 38%, transparent);
border-radius: 0.35em;
transition: background-color 0.25s ease, border-color 0.25s ease, transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.chk-todo-strikethrough-box svg {
width: 0.85em;
height: 0.85em;
fill: none;
stroke: #fff;
stroke-width: 3.4;
stroke-linecap: round;
stroke-linejoin: round;
stroke-dasharray: 20;
stroke-dashoffset: 20;
transition: stroke-dashoffset 0.2s ease-in;
}
.chk-todo-strikethrough-text {
position: relative;
transition: opacity 0.3s ease;
}
.chk-todo-strikethrough-text::after {
content: "";
position: absolute;
left: -0.15em;
right: -0.15em;
top: 53%;
height: 0.09em;
min-height: 1px;
border-radius: 1em;
background: currentColor;
transform: scaleX(0);
transform-origin: right;
transition: transform 0.3s cubic-bezier(0.65, 0, 0.35, 1);
}
.chk-todo-strikethrough:hover .chk-todo-strikethrough-box {
border-color: var(--c);
}
.chk-todo-strikethrough:active .chk-todo-strikethrough-box {
transform: scale(0.88);
}
.chk-todo-strikethrough input:checked + .chk-todo-strikethrough-box {
background: var(--c);
border-color: var(--c);
}
.chk-todo-strikethrough input:checked + .chk-todo-strikethrough-box svg {
stroke-dashoffset: 0;
transition: stroke-dashoffset 0.3s cubic-bezier(0.65, 0, 0.35, 1) 0.1s;
}
.chk-todo-strikethrough input:checked ~ .chk-todo-strikethrough-text {
opacity: 0.5;
transition-delay: 0.25s;
}
.chk-todo-strikethrough input:checked ~ .chk-todo-strikethrough-text::after {
transform: scaleX(1);
transform-origin: left;
transition: transform 0.45s cubic-bezier(0.65, 0, 0.35, 1) 0.15s;
}
.chk-todo-strikethrough input:focus-visible + .chk-todo-strikethrough-box {
outline: 0.12em solid var(--c);
outline-offset: 0.18em;
}
@media (prefers-reduced-motion: reduce) {
.chk-todo-strikethrough, .chk-todo-strikethrough *, .chk-todo-strikethrough::before, .chk-todo-strikethrough::after, .chk-todo-strikethrough *::before, .chk-todo-strikethrough *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}The same effect using Tailwind utility classes. No custom CSS or config needed.
<label class="relative inline-flex cursor-pointer select-none items-center gap-2.5">
<input type="checkbox" class="peer sr-only">
<span class="grid h-5 w-5 shrink-0 place-items-center rounded-md border-2 border-gray-400 transition-colors duration-200 peer-checked:border-blue-500 peer-checked:bg-blue-500 peer-focus-visible:ring-2 peer-focus-visible:ring-blue-500 peer-focus-visible:ring-offset-2 peer-checked:[&>svg]:[stroke-dashoffset:0]">
<svg viewBox="0 0 24 24" class="h-4 w-4 fill-none stroke-white stroke-[3.4] transition-[stroke-dashoffset] delay-100 duration-300 [stroke-dasharray:20] [stroke-dashoffset:20] [stroke-linecap:round] [stroke-linejoin:round]" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg>
</span>
<span class="relative transition-opacity duration-300 after:absolute after:inset-x-0 after:top-1/2 after:h-0.5 after:origin-right after:scale-x-0 after:rounded-full after:bg-current after:transition-transform after:duration-300 after:content-[''] peer-checked:opacity-50 peer-checked:after:origin-left peer-checked:after:scale-x-100">Call the dentist</span>
</label>--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.