Skip to content
Haze UI

Checkbox

A native checkbox with a label, optional description, and a mixed state for partially selected groups.

pnpm dlx shadcn@latest add @haze/checkbox
Open preview in a new tab
Livesmall script

When to use

  • Accepting terms or opting in to emails
  • Independent yes/no settings that are saved with a submit button
  • A list where several options can be on at once

When not to use

  • Settings that apply the moment they are flipped; use switch
  • Exactly one choice from a group; use radio-group

Installation

Add the Haze registry to components.json once, then install Checkbox with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.

pnpm dlx shadcn@latest add @haze/checkbox
First time? Registry and theme setup

1. Add to components.json:

{
  "registries": {
    "@haze": "http://localhost:4329/r/{name}.json"
  }
}

2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";

API reference

PropTypeDefaultDescription
id*string–Input id; the label's for and the description id (<id>-description) derive from it.
namestringidForm field name.
label*string–Visible label text.
descriptionstring–Secondary line; the input points at it with aria-describedby.
checkedboolean–Initial checked state.
indeterminateboolean–Shows a mixed state initially and after a form reset. Checked still determines the submitted value.
disabledboolean–Dims the box and its label (the description stays readable) and blocks input.
valuestring–Value submitted when checked; the browser default is "on".
classstring–Extra classes on the wrapper.
...restattributes–Any other input attribute, for example required or aria-invalid.

Keyboard interactions

Space
Toggles the checkbox
Tab
Moves to the next control

Accessibility

  • The input stays a real checkbox, so checked state, form submission and the label click target all come from the browser.
  • The mixed-state indicator uses the native indeterminate property. Without JavaScript the checked state remains available.
  • The check mark scales in over 200 ms and a press shrinks the box. The box border is foreground at 40%, which meets 3:1 against the surface.
  • In Windows forced-colors mode the custom drawing is dropped (appearance-auto) and the system checkbox shows instead.
  • The description is linked with aria-describedby only when it exists, so no dangling id reaches the accessibility tree.

Notes for AI

Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.

  • Install and use

    Install the Haze UI component "Checkbox" with `npx shadcn@latest add @haze/checkbox`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import Checkbox from "@/components/haze/ui/checkbox.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/checkbox.md

  • Customize with real content

    Adapt the Haze checkbox ui for our product. Replace the demo values of these props with our real content: id, name, label, description, checked, indeterminate, disabled, value, class, ...rest. Keep the layout, the heading level rules and these accessibility details: The input stays a real checkbox, so checked state, form submission and the label click target all come from the browser. The mixed-state indicator uses the native indeterminate property. Without JavaScript the checked state remains available. The check mark scales in over 200 ms and a press shrinks the box. The box border is foreground at 40%, which meets 3:1 against the surface. In Windows forced-colors mode the custom drawing is dropped (appearance-auto) and the system checkbox shows instead. The description is linked with aria-describedby only when it exists, so no dangling id reaches the accessibility tree. Do not add raw color classes; use the Haze tokens.

  • Choose the right block

    Before using checkbox, check it fits: use it when accepting terms or opting in to emails; independent yes/no settings that are saved with a submit button; a list where several options can be on at once. Avoid it when settings that apply the moment they are flipped; use switch; exactly one choice from a group; use radio-group. Alternatives: @haze/switch, @haze/radio-group, @haze/field.

Dependencies

  • npm: @lucide/astro
  • @haze/utils
  • @haze/theme (one-time setup)

Source · Original Haze UI work.

Catalog

↑↓ moveEnter openEsc close

Keyboard shortcuts

CtrlK
Command palette
/
Focus search
←↑→↓
Move between cards
jk
Next / previous card
ci
Copy code / install command (detail page)
[]
Previous / next entry
?
This help
Esc
Close dialog