Checkbox
A tick that draws itself in, plus indeterminate.
Variants
3 more takes on the checkbox, each a single file you install on its own by its id.
aui-052Add-on cards
Add-on cards with a rolling total.
$ pnpm dlx asta-ui@latest add checkbox-aui-052aui-053Task list
Tick a task and it moves to done.
$ pnpm dlx asta-ui@latest add checkbox-aui-053aui-054Permission tree
Nested permissions with role presets.
$ pnpm dlx asta-ui@latest add checkbox-aui-054Installation
Run the CLI
Run
pnpm dlx asta-ui@latest initonce, then this. The file lands incomponents/astabyte/, installsradix-ui@base-ui/reactand the colour tokens go into your CSS. This is the Radix build. Drop --radix for Base UI.This is the Base UI build, the default. Want Radix? Add --radix.$ pnpm dlx asta-ui@latest add checkbox --radixOr install the package
Don’t want the file? Import from
asta-uiasta-ui/baseand update withpnpm update asta-ui. Add the stylesheet once. More.$ pnpm add asta-ui radix-ui @base-ui/reactimport { Checkbox } from "asta-ui";import { Checkbox } from "asta-ui/base";Or copy it by hand
Install
radix-ui@base-ui/react, then copy this file. Keep the paths, or fix the@/imports. Then add the tokens fromglobals.css."use client"; import { Checkbox as C } from "radix-ui"; import { useId, useState, type ReactNode } from "react"; const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" "); export type CheckedState = boolean | "indeterminate"; export interface CheckboxProps { checked?: CheckedState; defaultChecked?: CheckedState; onCheckedChange?: (checked: boolean) => void; disabled?: boolean; label?: ReactNode; description?: ReactNode; id?: string; name?: string; className?: string; } /** * A checkbox on Radix Checkbox (ARIA, Space to toggle, native form value through `name`) whose tick draws * itself in. `indeterminate` shows a dash (for select-all rows). */ export function Checkbox({ checked, defaultChecked = false, onCheckedChange, disabled, label, description, id, name, className }: CheckboxProps) { const auto = useId(); const cid = id ?? auto; const [inner, setInner] = useState<CheckedState>(defaultChecked); const state = checked ?? inner; const on = state === true; const mixed = state === "indeterminate"; const box = ( <C.Root id={cid} name={name} checked={state} onCheckedChange={(v) => { const next = v === true; // indeterminate → checked if (checked === undefined) setInner(next); onCheckedChange?.(next); }} aria-describedby={description ? `${cid}-d` : undefined} disabled={disabled} className={cx( "group/cb relative grid h-[18px] w-[18px] shrink-0 place-items-center rounded-[6px] outline-none transition-[background-color,box-shadow,transform] duration-200 active:scale-90", "focus-visible:ring-2 focus-visible:ring-brand/50 focus-visible:ring-offset-2 focus-visible:ring-offset-paper disabled:opacity-45", on || mixed ? "bg-brand shadow-[inset_0_1px_0_rgb(255_255_255/0.2),0_1px_2px_rgb(0_0_0/0.2)]" : "bg-paper shadow-[inset_0_0_0_1.5px_color-mix(in_srgb,var(--color-ink)_22%,transparent)] hover:shadow-[inset_0_0_0_1.5px_color-mix(in_srgb,var(--color-ink)_40%,transparent)]", )} > <svg viewBox="0 0 24 24" className="col-start-1 row-start-1 h-3 w-3 text-on-brand" fill="none" stroke="currentColor" strokeWidth="3.6" strokeLinecap="round" strokeLinejoin="round" aria-hidden> <path d="m5 12.5 4.5 4.5L19 7.5" pathLength={1} strokeDasharray="1" className="transition-[stroke-dashoffset] ease-[cubic-bezier(.16,1,.3,1)] motion-reduce:transition-none" style={{ strokeDashoffset: on ? 0 : 1, transitionDuration: on ? "420ms" : "120ms" }} /> </svg> <span aria-hidden className={cx("col-start-1 row-start-1 h-[2.2px] w-2 rounded-full bg-on-brand transition-transform duration-300 ease-[cubic-bezier(.16,1,.3,1)]", mixed ? "scale-x-100" : "scale-x-0")} /> </C.Root> ); if (!label) return <span className={className}>{box}</span>; return ( <div className={cx("flex items-start", disabled && "opacity-60", className)}> {/* The box sits in a label too, so the gap to the text is part of one hit target. */} <label htmlFor={cid} className={cx("pr-3 pt-[1px]", !disabled && "cursor-pointer")}> {box} </label> <span className="min-w-0"> <label htmlFor={cid} className={cx("block select-none text-[14px] leading-5 text-ink", !disabled && "cursor-pointer")}> {label} </label> {description && ( <span id={`${cid}-d`} className="mt-0.5 block text-[13px] leading-snug text-mute"> {description} </span> )} </span> </div> ); } export default Checkbox;"use client"; import { Checkbox as C } from "@base-ui/react/checkbox"; import { useId, useState, type ReactNode } from "react"; const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" "); export type CheckedState = boolean | "indeterminate"; export interface CheckboxProps { checked?: CheckedState; defaultChecked?: CheckedState; onCheckedChange?: (checked: boolean) => void; disabled?: boolean; label?: ReactNode; description?: ReactNode; id?: string; name?: string; className?: string; } /** * A checkbox on Base UI Checkbox (ARIA, Space to toggle, native form value through `name`) whose tick draws * itself in. `indeterminate` shows a dash (for select-all rows). */ export function Checkbox({ checked, defaultChecked = false, onCheckedChange, disabled, label, description, id, name, className }: CheckboxProps) { const auto = useId(); const cid = id ?? auto; const [inner, setInner] = useState<CheckedState>(defaultChecked); const state = checked ?? inner; const on = state === true; const mixed = state === "indeterminate"; const box = ( <C.Root id={cid} name={name} checked={on} indeterminate={mixed} onCheckedChange={(v) => { const next = mixed ? true : v; // indeterminate → checked if (checked === undefined) setInner(next); onCheckedChange?.(next); }} aria-describedby={description ? `${cid}-d` : undefined} disabled={disabled} className={cx( "group/cb relative grid h-[18px] w-[18px] shrink-0 place-items-center rounded-[6px] outline-none transition-[background-color,box-shadow,transform] duration-200 active:scale-90", "focus-visible:ring-2 focus-visible:ring-brand/50 focus-visible:ring-offset-2 focus-visible:ring-offset-paper disabled:opacity-45", on || mixed ? "bg-brand shadow-[inset_0_1px_0_rgb(255_255_255/0.2),0_1px_2px_rgb(0_0_0/0.2)]" : "bg-paper shadow-[inset_0_0_0_1.5px_color-mix(in_srgb,var(--color-ink)_22%,transparent)] hover:shadow-[inset_0_0_0_1.5px_color-mix(in_srgb,var(--color-ink)_40%,transparent)]", )} > <svg viewBox="0 0 24 24" className="col-start-1 row-start-1 h-3 w-3 text-on-brand" fill="none" stroke="currentColor" strokeWidth="3.6" strokeLinecap="round" strokeLinejoin="round" aria-hidden> <path d="m5 12.5 4.5 4.5L19 7.5" pathLength={1} strokeDasharray="1" className="transition-[stroke-dashoffset] ease-[cubic-bezier(.16,1,.3,1)] motion-reduce:transition-none" style={{ strokeDashoffset: on ? 0 : 1, transitionDuration: on ? "420ms" : "120ms" }} /> </svg> <span aria-hidden className={cx("col-start-1 row-start-1 h-[2.2px] w-2 rounded-full bg-on-brand transition-transform duration-300 ease-[cubic-bezier(.16,1,.3,1)]", mixed ? "scale-x-100" : "scale-x-0")} /> </C.Root> ); if (!label) return <span className={className}>{box}</span>; return ( <div className={cx("flex items-start", disabled && "opacity-60", className)}> {/* The box sits in a label too, so the gap to the text is part of one hit target. */} <label htmlFor={cid} className={cx("pr-3 pt-[1px]", !disabled && "cursor-pointer")}> {box} </label> <span className="min-w-0"> <label htmlFor={cid} className={cx("block select-none text-[14px] leading-5 text-ink", !disabled && "cursor-pointer")}> {label} </label> {description && ( <span id={`${cid}-d`} className="mt-0.5 block text-[13px] leading-snug text-mute"> {description} </span> )} </span> </div> ); } export default Checkbox;Or ask your AI agent
Paste this into Claude Code, Cursor, Codex, v0 or Lovable. Fill in the last line. More in Prompts.
Add the Astabyte UI Checkbox component to my project. A tick that draws itself in, plus indeterminate. It includes: checked, indeterminate, disabled. Install it (Radix build): ```sh pnpm dlx asta-ui@latest add checkbox --radix ``` Or with the shadcn CLI: ```sh pnpm dlx shadcn@latest add https://ui.astabyte.com/r/checkbox.json ``` If the project isn't set up yet, run `pnpm dlx asta-ui@latest init --radix` first: it runs `shadcn init` when needed and adds the @astabyte registry (Next.js, Vite, React Router, Astro, TanStack Start; Tailwind CSS v4). Import it like this: ```tsx import { Checkbox } from "@/components/astabyte/checkbox"; ``` Usage example and props: https://ui.astabyte.com/checkbox Full catalogue for context: https://ui.astabyte.com/llms.txt Rules: - Keep the colour tokens (paper, paper-2, ink, ink-2, mute, brand). Don't restyle with hard-coded colours; rebrand by changing the token values in the CSS. - Keep the motion as it is: transform and opacity only, and the prefers-reduced-motion fallback. - Keep keyboard, focus and ARIA behaviour (interactive pieces are built on Radix primitives from the radix-ui package). - Stay on Radix: install other Astabyte UI components with `--radix` so the project uses one primitive library. - Use fake data and fake brand names in examples. Use it to: [describe where it goes and what it should do]Add the Astabyte UI Checkbox component to my project. A tick that draws itself in, plus indeterminate. It includes: checked, indeterminate, disabled. Install it (Base UI build): ```sh pnpm dlx asta-ui@latest add checkbox ``` Or with the shadcn CLI: ```sh pnpm dlx shadcn@latest add https://ui.astabyte.com/r/base/checkbox.json ``` If the project isn't set up yet, run `pnpm dlx asta-ui@latest init` first: it runs `shadcn init` when needed and adds the @astabyte registry (Next.js, Vite, React Router, Astro, TanStack Start; Tailwind CSS v4). Import it like this: ```tsx import { Checkbox } from "@/components/astabyte/checkbox"; ``` Usage example and props: https://ui.astabyte.com/checkbox Full catalogue for context: https://ui.astabyte.com/llms.txt Rules: - Keep the colour tokens (paper, paper-2, ink, ink-2, mute, brand). Don't restyle with hard-coded colours; rebrand by changing the token values in the CSS. - Keep the motion as it is: transform and opacity only, and the prefers-reduced-motion fallback. - Keep keyboard, focus and ARIA behaviour (interactive pieces are built on Base UI primitives from the @base-ui/react package). - Stay on Base UI: install other Astabyte UI components without `--radix` so the project uses one primitive library. - Use fake data and fake brand names in examples. Use it to: [describe where it goes and what it should do]Or use plain HTML + CSS
Not on React? Use it from Django, Rails, Laravel, Go
html/template, htmx or a static page. Loadasta.cssandasta.jsonce (thehead.htmltab), then paste the markup. Theui.astabyte.com/cdnlink is temporary: pin a version from jsDelivr for production. More in HTML + CSS.<div style="display:grid;gap:12px"> <label class="asta-checkbox"> <span class="asta-checkbox-box"><input type="checkbox" class="asta-checkbox-input" name="updates" checked><svg class="asta-checkbox-check" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3.5 8.5l3 3 6-7"/></svg><span class="asta-checkbox-dash" aria-hidden="true"></span></span> <span><span class="asta-checkbox-label">Email me product updates</span><span class="asta-checkbox-desc">Once a month from Astabyte. No spam.</span></span> </label> <label class="asta-checkbox"> <span class="asta-checkbox-box"><input type="checkbox" class="asta-checkbox-input" name="all" data-indeterminate><svg class="asta-checkbox-check" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3.5 8.5l3 3 6-7"/></svg><span class="asta-checkbox-dash" aria-hidden="true"></span></span> <span><span class="asta-checkbox-label">Select all projects</span></span> </label> </div>
Usage
The demo above, as code.
"use client";
import { useState } from "react";
import { Checkbox } from "@/components/astabyte/checkbox";
const TASKS = ["Pick the type scale", "Draw the empty states", "Tune the button press", "Write the release notes"];
export default function CheckboxDemo() {
const [done, setDone] = useState<boolean[]>([true, false, true, false]);
const count = done.filter(Boolean).length;
const all = count === done.length ? true : count === 0 ? false : "indeterminate";
return (
<div className="flex min-h-[420px] w-full items-center justify-center p-6 sm:p-10">
<div className="flex w-full max-w-sm flex-col gap-6">
<div className="rounded-xl bg-paper p-2 shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_10%,transparent)]">
<div className="flex items-center justify-between rounded-[10px] bg-paper-2 px-3 py-2.5">
<Checkbox label="Launch checklist" checked={all} onCheckedChange={(v) => setDone(done.map(() => v))} />
<span className="font-mono text-[11px] tabular-nums text-mute">
{count}/{done.length}
</span>
</div>
<ul className="flex flex-col py-1">
{TASKS.map((t, i) => (
<li key={t} className="px-3 py-2">
<Checkbox
checked={done[i]}
onCheckedChange={(v) => setDone(done.map((d, j) => (j === i ? v : d)))}
label={<span className={`transition-colors duration-300 ${done[i] ? "text-mute line-through decoration-mute/60" : ""}`}>{t}</span>}
/>
</li>
))}
</ul>
</div>
<div className="flex flex-col gap-4 px-1">
<Checkbox defaultChecked label="Email me about new components" description="About once a month. Unsubscribe any time." />
<Checkbox disabled label="Disabled" />
</div>
</div>
</div>
);
}