Swipe
import { useState } from 'react';
const css = `
@keyframes cb-swipe-done {
0% { transform: translateX(0); animation-timing-function: cubic-bezier(0.3, 0, 0.2, 1); }
38% { transform: translateX(54px); }
55% { transform: translateX(54px); animation-timing-function: cubic-bezier(0.5, 0, 0.3, 1.4); }
100% { transform: translateX(0); }
}
@keyframes cb-swipe-undo { 0% { transform: translateX(0); } 30% { transform: translateX(-8px); } 100% { transform: translateX(0); } }
@keyframes cb-swipe-pop { 0%, 15% { transform: scale(0.4); opacity: 0; } 40% { transform: scale(1.15); opacity: 1; } 55%, 100% { transform: scale(1); opacity: 1; } }
.cb-swipe { position: relative; display: inline-flex; color: light-dark(#42454c, #e5e6e9); font-size: 14px; cursor: pointer; user-select: none; }
.cb-swipe__input { position: absolute; width: 1px; height: 1px; margin: 0; opacity: 0; }
.cb-swipe__row { position: relative; display: block; width: 190px; height: 42px; overflow: hidden; border-radius: 11px; background: light-dark(#dbdde1, #2e3035); }
.cb-swipe__input:focus-visible + .cb-swipe__row { outline: 2px solid light-dark(#5f626a, #a7abb2); outline-offset: 3px; }
.cb-swipe__under { position: absolute; left: 16px; top: 11px; width: 20px; height: 20px; opacity: 0; }
.cb-swipe__under path { fill: none; stroke: light-dark(#373a40, #f1f2f3); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.cb-swipe__card {
position: absolute;
inset: 0;
display: flex;
align-items: center;
gap: 10px;
padding: 0 14px;
border-radius: 11px;
background: light-dark(#ebedf0, #232529);
box-shadow: inset 0 0 0 1px light-dark(#cbced3, #393c41), 0 2px 6px -2px color-mix(in oklab, light-dark(#fbfcfd, #121417) 70%, transparent);
}
.cb-swipe__dot {
position: relative;
flex: none;
width: 18px;
height: 18px;
border-radius: 50%;
box-shadow: inset 0 0 0 1.5px light-dark(#6d7179, #7d8087);
transition: background-color 0.2s, box-shadow 0.2s;
}
.cb-swipe__dot svg { position: absolute; inset: 0; width: 18px; height: 18px; }
.cb-swipe__dot path { fill: none; stroke: light-dark(#f3f4f7, #1a1c1f); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; opacity: 0; transition: opacity 0.2s; }
.cb-swipe__text {
background: linear-gradient(currentColor, currentColor) 0 55% / 0% 1.5px no-repeat;
transition: background-size 0.25s ease, color 0.25s ease;
}
.cb-swipe__input:checked + .cb-swipe__row .cb-swipe__dot { background: light-dark(#373a40, #f1f2f3); box-shadow: inset 0 0 0 1.5px light-dark(#373a40, #f1f2f3); transition-delay: 0.5s; }
.cb-swipe__input:checked + .cb-swipe__row .cb-swipe__dot path { opacity: 1; transition-delay: 0.5s; }
.cb-swipe__input:checked + .cb-swipe__row .cb-swipe__text { color: light-dark(#5f626a, #a7abb2); background-size: 100% 1.5px; transition: background-size 0.35s ease 0.55s, color 0.3s ease 0.55s; }
.cb-swipe[data-armed] .cb-swipe__input:checked + .cb-swipe__row .cb-swipe__card { animation: cb-swipe-done 0.8s; }
.cb-swipe[data-armed] .cb-swipe__input:checked + .cb-swipe__row .cb-swipe__under { animation: cb-swipe-pop 0.8s ease-out; }
.cb-swipe[data-armed] .cb-swipe__input:not(:checked) + .cb-swipe__row .cb-swipe__card { animation: cb-swipe-undo 0.35s ease-out; }
@media (prefers-reduced-motion: reduce) {
.cb-swipe__row * { animation: none !important; transition-duration: 0.01s !important; transition-delay: 0s !important; }
}
`;
export function SwipeCheckbox() {
const [armed, setArmed] = useState(false);
return (
<>
<style>
{css}
</style>
<label className="cb-swipe" data-armed={armed || undefined}>
<input className="cb-swipe__input" type="checkbox" onChange={() => setArmed(true)} />
<span className="cb-swipe__row">
<svg className="cb-swipe__under" viewBox="0 0 20 20" aria-hidden="true">
<path d="M4 10.5L8 14.5L16 5.5" />
</svg>
<span className="cb-swipe__card">
<span className="cb-swipe__dot" aria-hidden="true">
<svg viewBox="0 0 18 18">
<path d="M5 9.2L7.8 12L13 6.2" />
</svg>
</span>
<span className="cb-swipe__text">Water the plants</span>
</span>
</span>
</label>
</>
);
}Markup where the component goes, CSS in your stylesheet, script before </body>. In Vue, Svelte or Angular, call initCbSwipe(el) on the mounted element instead.
<label class="cb-swipe">
<input class="cb-swipe__input" type="checkbox"/>
<span class="cb-swipe__row">
<svg class="cb-swipe__under" viewBox="0 0 20 20" aria-hidden="true">
<path d="M4 10.5L8 14.5L16 5.5"></path>
</svg>
<span class="cb-swipe__card">
<span class="cb-swipe__dot" aria-hidden="true">
<svg viewBox="0 0 18 18">
<path d="M5 9.2L7.8 12L13 6.2"></path>
</svg>
</span>
<span class="cb-swipe__text">Water the plants</span>
</span>
</span>
</label>@keyframes cb-swipe-done {
0% { transform: translateX(0); animation-timing-function: cubic-bezier(0.3, 0, 0.2, 1); }
38% { transform: translateX(54px); }
55% { transform: translateX(54px); animation-timing-function: cubic-bezier(0.5, 0, 0.3, 1.4); }
100% { transform: translateX(0); }
}
@keyframes cb-swipe-undo { 0% { transform: translateX(0); } 30% { transform: translateX(-8px); } 100% { transform: translateX(0); } }
@keyframes cb-swipe-pop { 0%, 15% { transform: scale(0.4); opacity: 0; } 40% { transform: scale(1.15); opacity: 1; } 55%, 100% { transform: scale(1); opacity: 1; } }
.cb-swipe { position: relative; display: inline-flex; color: light-dark(#42454c, #e5e6e9); font-size: 14px; cursor: pointer; user-select: none; }
.cb-swipe__input { position: absolute; width: 1px; height: 1px; margin: 0; opacity: 0; }
.cb-swipe__row { position: relative; display: block; width: 190px; height: 42px; overflow: hidden; border-radius: 11px; background: light-dark(#dbdde1, #2e3035); }
.cb-swipe__input:focus-visible + .cb-swipe__row { outline: 2px solid light-dark(#5f626a, #a7abb2); outline-offset: 3px; }
.cb-swipe__under { position: absolute; left: 16px; top: 11px; width: 20px; height: 20px; opacity: 0; }
.cb-swipe__under path { fill: none; stroke: light-dark(#373a40, #f1f2f3); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.cb-swipe__card {
position: absolute;
inset: 0;
display: flex;
align-items: center;
gap: 10px;
padding: 0 14px;
border-radius: 11px;
background: light-dark(#ebedf0, #232529);
box-shadow: inset 0 0 0 1px light-dark(#cbced3, #393c41), 0 2px 6px -2px color-mix(in oklab, light-dark(#fbfcfd, #121417) 70%, transparent);
}
.cb-swipe__dot {
position: relative;
flex: none;
width: 18px;
height: 18px;
border-radius: 50%;
box-shadow: inset 0 0 0 1.5px light-dark(#6d7179, #7d8087);
transition: background-color 0.2s, box-shadow 0.2s;
}
.cb-swipe__dot svg { position: absolute; inset: 0; width: 18px; height: 18px; }
.cb-swipe__dot path { fill: none; stroke: light-dark(#f3f4f7, #1a1c1f); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; opacity: 0; transition: opacity 0.2s; }
.cb-swipe__text {
background: linear-gradient(currentColor, currentColor) 0 55% / 0% 1.5px no-repeat;
transition: background-size 0.25s ease, color 0.25s ease;
}
.cb-swipe__input:checked + .cb-swipe__row .cb-swipe__dot { background: light-dark(#373a40, #f1f2f3); box-shadow: inset 0 0 0 1.5px light-dark(#373a40, #f1f2f3); transition-delay: 0.5s; }
.cb-swipe__input:checked + .cb-swipe__row .cb-swipe__dot path { opacity: 1; transition-delay: 0.5s; }
.cb-swipe__input:checked + .cb-swipe__row .cb-swipe__text { color: light-dark(#5f626a, #a7abb2); background-size: 100% 1.5px; transition: background-size 0.35s ease 0.55s, color 0.3s ease 0.55s; }
.cb-swipe[data-armed] .cb-swipe__input:checked + .cb-swipe__row .cb-swipe__card { animation: cb-swipe-done 0.8s; }
.cb-swipe[data-armed] .cb-swipe__input:checked + .cb-swipe__row .cb-swipe__under { animation: cb-swipe-pop 0.8s ease-out; }
.cb-swipe[data-armed] .cb-swipe__input:not(:checked) + .cb-swipe__row .cb-swipe__card { animation: cb-swipe-undo 0.35s ease-out; }
@media (prefers-reduced-motion: reduce) {
.cb-swipe__row * { animation: none !important; transition-duration: 0.01s !important; transition-delay: 0s !important; }
}function initCbSwipe(root) {
var input = root.querySelector('input');
if (!input) return;
// Animate only after the first change, so nothing plays on page load.
function arm() { root.setAttribute('data-armed', ''); }
input.addEventListener('change', arm);
return function () { input.removeEventListener('change', arm); };
}
document.querySelectorAll('.cb-swipe').forEach(initCbSwipe);Goal: Create a "Swipe" checkbox.
Visual behavior: A swipe-to-complete checkbox: ticking slides the task card aside to show a tick beneath, springs it back, fills its circle and strikes the text through; unticking nudges it the other way.
Technique:
- A real native checkbox (visually hidden: absolute, 1x1, opacity 0) inside a <label>; every visual is aria-hidden and styled from the input with :checked + sibling selectors.
- The card slides on a keyframe over a row that clips it; the tick under it pops in as it is revealed.
- The strike-through is a 1.5px linear-gradient background that grows across the text.
- The keyframes only apply once a data-armed flag is set on the first change, so nothing plays on page load; ticking and unticking use differently named keyframes, so each change restarts the right one.
Accessibility: A native checkbox inside a <label>, so Space toggles it and the visible label names it; :focus-visible on the input outlines the visual. Under prefers-reduced-motion the card does not move.
My stack: {{USER_STACK}}
My styling: {{USER_STYLING}}
My constraints: {{USER_CONSTRAINTS}}
My colors: neutral only. Black, white and grays, no hues. Use the color values above as written, or my project's closest neutral tokens.
Return a single self-contained component. No dependencies.Goal: Create a "Swipe" checkbox.
Visual behavior: A swipe-to-complete checkbox: ticking slides the task card aside to show a tick beneath, springs it back, fills its circle and strikes the text through; unticking nudges it the other way.
Technique:
- A real native checkbox (visually hidden: absolute, 1x1, opacity 0) inside a <label>; every visual is aria-hidden and styled from the input with :checked + sibling selectors.
- The card slides on a keyframe over a row that clips it; the tick under it pops in as it is revealed.
- The strike-through is a 1.5px linear-gradient background that grows across the text.
- The keyframes only apply once a data-armed flag is set on the first change, so nothing plays on page load; ticking and unticking use differently named keyframes, so each change restarts the right one.
Accessibility: A native checkbox inside a <label>, so Space toggles it and the visible label names it; :focus-visible on the input outlines the visual. Under prefers-reduced-motion the card does not move.
My stack: {{USER_STACK}}
My styling: {{USER_STYLING}}
My constraints: {{USER_CONSTRAINTS}}
My colors: use my project's existing color tokens. The color values above are grayscale placeholders. Map each one by its role (surface, text, border, accent, glow) to my theme, and keep their relative lightness so contrast and the effect still read.
Return a single self-contained component. No dependencies.Paste into Claude, ChatGPT or Cursor after filling in {{USER_STACK}}, {{USER_STYLING}} and {{USER_CONSTRAINTS}}. Neutral keeps the greys you see here; Match my project asks the model to map them onto your own colour tokens.
Free to use in any project, commercial included. MIT-0, no attribution required. Licence
About this component
A swipe-to-complete checkbox: ticking slides the task card aside to show a tick beneath, springs it back, fills its circle and strikes the text through; unticking nudges it the other way.
- Dependencies
- None
- Difficulty
- Beginner
- Triggers
- click, state change, card
- Techniques
- keyframes, gradient, css transition
- Reduced motion
- Respected
- Theme
- Light and dark (follows your page's color-scheme)
A native checkbox inside a <label>, so Space toggles it and the visible label names it; :focus-visible on the input outlines the visual. Under prefers-reduced-motion the card does not move.