Markdown
import { useState } from 'react';
const css = `
@keyframes cb-markdown-caret { 0%, 22% { opacity: 1; } 23%, 44% { opacity: 0; } 45%, 66% { opacity: 1; } 67%, 88% { opacity: 0; } 89%, 99% { opacity: 1; } 100% { opacity: 0; } }
@keyframes cb-markdown-caret-b { 0%, 22% { opacity: 1; } 23%, 44% { opacity: 0; } 45%, 66% { opacity: 1; } 67%, 88% { opacity: 0; } 89%, 99% { opacity: 1; } 100% { opacity: 0; } }
@keyframes cb-markdown-type { 0%, 30% { opacity: 0; transform: translateY(-3px) scale(1.4); } 40% { opacity: 1; transform: none; } 100% { opacity: 1; transform: none; } }
@keyframes cb-markdown-delete { 0%, 30% { opacity: 1; } 31%, 100% { opacity: 0; } }
.cb-markdown {
position: relative;
display: inline-flex;
align-items: center;
gap: 0.6ch;
padding: 8px 12px;
border-radius: 8px;
background: light-dark(#f3f4f7, #1a1c1f);
box-shadow: inset 0 0 0 1px light-dark(#dbdde1, #2e3035);
color: light-dark(#42454c, #e5e6e9);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 13px;
cursor: pointer;
user-select: none;
}
.cb-markdown__input { position: absolute; width: 1px; height: 1px; margin: 0; opacity: 0; }
.cb-markdown__dash { color: light-dark(#5f626a, #a7abb2); }
.cb-markdown__box { position: relative; display: inline-flex; color: light-dark(#5f626a, #a7abb2); border-radius: 3px; }
.cb-markdown__input:focus-visible + .cb-markdown__dash + .cb-markdown__box { outline: 2px solid light-dark(#5f626a, #a7abb2); outline-offset: 2px; }
.cb-markdown__slot { position: relative; display: inline-block; width: 1ch; text-align: center; }
.cb-markdown__x { display: inline-block; color: light-dark(#373a40, #f1f2f3); font-weight: 600; opacity: 0; }
.cb-markdown__caret {
position: absolute;
left: 100%;
top: 2px;
bottom: 2px;
width: 1.5px;
margin-left: -0.5px;
background: light-dark(#373a40, #f1f2f3);
opacity: 0;
}
.cb-markdown__text { transition: color 0.3s; }
.cb-markdown__input:checked ~ .cb-markdown__box .cb-markdown__x { opacity: 1; }
.cb-markdown__input:checked ~ .cb-markdown__text { color: light-dark(#5f626a, #a7abb2); }
.cb-markdown[data-armed] .cb-markdown__input:checked ~ .cb-markdown__box .cb-markdown__x { animation: cb-markdown-type 0.9s ease-out; }
.cb-markdown[data-armed] .cb-markdown__input:not(:checked) ~ .cb-markdown__box .cb-markdown__x { animation: cb-markdown-delete 0.9s linear; }
/* The same blink both ways, under two names so the browser restarts it on every change. */
.cb-markdown[data-armed] .cb-markdown__input:checked ~ .cb-markdown__box .cb-markdown__caret { animation: cb-markdown-caret 0.9s linear; }
.cb-markdown[data-armed] .cb-markdown__input:not(:checked) ~ .cb-markdown__box .cb-markdown__caret { animation: cb-markdown-caret-b 0.9s linear; }
@media (prefers-reduced-motion: reduce) {
.cb-markdown * { animation: none !important; transition-duration: 0.01s !important; }
}
`;
export function MarkdownCheckbox() {
const [armed, setArmed] = useState(false);
return (
<>
<style>
{css}
</style>
<label className="cb-markdown" data-armed={armed || undefined}>
<input className="cb-markdown__input" type="checkbox" onChange={() => setArmed(true)} />
<span className="cb-markdown__dash" aria-hidden="true">
-
</span>
<span className="cb-markdown__box" aria-hidden="true">
[
<span className="cb-markdown__slot">
<span className="cb-markdown__x">x</span>
<span className="cb-markdown__caret" />
</span>
]
</span>
<span className="cb-markdown__text">Ship the release</span>
</label>
</>
);
}Markup where the component goes, CSS in your stylesheet, script before </body>. In Vue, Svelte or Angular, call initCbMarkdown(el) on the mounted element instead.
<label class="cb-markdown">
<input class="cb-markdown__input" type="checkbox"/>
<span class="cb-markdown__dash" aria-hidden="true">-</span>
<span class="cb-markdown__box" aria-hidden="true">[<span class="cb-markdown__slot"><span class="cb-markdown__x">x</span><span class="cb-markdown__caret"></span></span>]</span>
<span class="cb-markdown__text">Ship the release</span>
</label>@keyframes cb-markdown-caret { 0%, 22% { opacity: 1; } 23%, 44% { opacity: 0; } 45%, 66% { opacity: 1; } 67%, 88% { opacity: 0; } 89%, 99% { opacity: 1; } 100% { opacity: 0; } }
@keyframes cb-markdown-caret-b { 0%, 22% { opacity: 1; } 23%, 44% { opacity: 0; } 45%, 66% { opacity: 1; } 67%, 88% { opacity: 0; } 89%, 99% { opacity: 1; } 100% { opacity: 0; } }
@keyframes cb-markdown-type { 0%, 30% { opacity: 0; transform: translateY(-3px) scale(1.4); } 40% { opacity: 1; transform: none; } 100% { opacity: 1; transform: none; } }
@keyframes cb-markdown-delete { 0%, 30% { opacity: 1; } 31%, 100% { opacity: 0; } }
.cb-markdown {
position: relative;
display: inline-flex;
align-items: center;
gap: 0.6ch;
padding: 8px 12px;
border-radius: 8px;
background: light-dark(#f3f4f7, #1a1c1f);
box-shadow: inset 0 0 0 1px light-dark(#dbdde1, #2e3035);
color: light-dark(#42454c, #e5e6e9);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 13px;
cursor: pointer;
user-select: none;
}
.cb-markdown__input { position: absolute; width: 1px; height: 1px; margin: 0; opacity: 0; }
.cb-markdown__dash { color: light-dark(#5f626a, #a7abb2); }
.cb-markdown__box { position: relative; display: inline-flex; color: light-dark(#5f626a, #a7abb2); border-radius: 3px; }
.cb-markdown__input:focus-visible + .cb-markdown__dash + .cb-markdown__box { outline: 2px solid light-dark(#5f626a, #a7abb2); outline-offset: 2px; }
.cb-markdown__slot { position: relative; display: inline-block; width: 1ch; text-align: center; }
.cb-markdown__x { display: inline-block; color: light-dark(#373a40, #f1f2f3); font-weight: 600; opacity: 0; }
.cb-markdown__caret {
position: absolute;
left: 100%;
top: 2px;
bottom: 2px;
width: 1.5px;
margin-left: -0.5px;
background: light-dark(#373a40, #f1f2f3);
opacity: 0;
}
.cb-markdown__text { transition: color 0.3s; }
.cb-markdown__input:checked ~ .cb-markdown__box .cb-markdown__x { opacity: 1; }
.cb-markdown__input:checked ~ .cb-markdown__text { color: light-dark(#5f626a, #a7abb2); }
.cb-markdown[data-armed] .cb-markdown__input:checked ~ .cb-markdown__box .cb-markdown__x { animation: cb-markdown-type 0.9s ease-out; }
.cb-markdown[data-armed] .cb-markdown__input:not(:checked) ~ .cb-markdown__box .cb-markdown__x { animation: cb-markdown-delete 0.9s linear; }
/* The same blink both ways, under two names so the browser restarts it on every change. */
.cb-markdown[data-armed] .cb-markdown__input:checked ~ .cb-markdown__box .cb-markdown__caret { animation: cb-markdown-caret 0.9s linear; }
.cb-markdown[data-armed] .cb-markdown__input:not(:checked) ~ .cb-markdown__box .cb-markdown__caret { animation: cb-markdown-caret-b 0.9s linear; }
@media (prefers-reduced-motion: reduce) {
.cb-markdown * { animation: none !important; transition-duration: 0.01s !important; }
}function initCbMarkdown(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-markdown').forEach(initCbMarkdown);Goal: Create a "Markdown" checkbox.
Visual behavior: A Markdown task checkbox: ticking blinks a caret between the brackets and types an x into them; unticking deletes it, and the task text dims while it is done.
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 x and the caret are spans inside the brackets; the caret blinks on a keyframe and the x appears partway through it, as if typed.
- 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 x changes instantly.
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 "Markdown" checkbox.
Visual behavior: A Markdown task checkbox: ticking blinks a caret between the brackets and types an x into them; unticking deletes it, and the task text dims while it is done.
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 x and the caret are spans inside the brackets; the caret blinks on a keyframe and the x appears partway through it, as if typed.
- 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 x changes instantly.
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 Markdown task checkbox: ticking blinks a caret between the brackets and types an x into them; unticking deletes it, and the task text dims while it is done.
- Dependencies
- None
- Difficulty
- Beginner
- Triggers
- click, state change
- Techniques
- keyframes
- 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 x changes instantly.