Checkbox
---import { Checkbox } from "@/components/starwind/checkbox";---
<Checkbox id="demo-checkbox" label="Checkbox" />import { Checkbox } from "@/components/starwind/checkbox";
export function Example() { return ( <Checkbox id="demo-checkbox" label="Checkbox" /> );}<script setup lang="ts">import { Checkbox } from "@/components/starwind/checkbox";</script>
<template> <Checkbox id="demo-checkbox" label="Checkbox" /></template><script lang="ts"> import { Checkbox } from "@/components/starwind/checkbox";</script>
<Checkbox id="docs-checkbox-demo-checkbox" label="Checkbox" />Installation
pnpx starwind@latest add checkbox --framework astronpx starwind@latest add checkbox --framework astroyarn dlx starwind@latest add checkbox --framework astropnpx starwind@latest add checkbox --framework reactnpx starwind@latest add checkbox --framework reactyarn dlx starwind@latest add checkbox --framework reactpnpx starwind@latest add checkbox --framework vuenpx starwind@latest add checkbox --framework vueyarn dlx starwind@latest add checkbox --framework vuepnpx starwind@latest add checkbox --framework sveltenpx starwind@latest add checkbox --framework svelteyarn dlx starwind@latest add checkbox --framework svelteUsage
---import { Checkbox } from "@/components/starwind/checkbox";---
<Checkbox id="demo-checkbox" label="Checkbox" />import { Checkbox } from "@/components/starwind/checkbox";
export function Example() { return ( <Checkbox id="demo-checkbox" label="Checkbox" /> );}<script setup lang="ts">import { Checkbox } from "@/components/starwind/checkbox";</script>
<template> <Checkbox id="demo-checkbox" label="Checkbox" /></template><script lang="ts"> import { Checkbox } from "@/components/starwind/checkbox";</script>
<Checkbox id="demo-checkbox" label="Checkbox" />Variants
---import { Checkbox } from "@/components/starwind/checkbox";---
<Checkbox id="default" label="Default" variant="default" defaultChecked /><Checkbox id="primary" label="Primary" variant="primary" defaultChecked /><Checkbox id="secondary" label="Secondary" variant="secondary" defaultChecked /><Checkbox id="info" label="Info" variant="info" defaultChecked /><Checkbox id="success" label="Success" variant="success" defaultChecked /><Checkbox id="warning" label="Warning" variant="warning" defaultChecked /><Checkbox id="error" label="Error" variant="error" defaultChecked />import { Checkbox } from "@/components/starwind/checkbox";
export function Example() { return ( <> <Checkbox id="default" label="Default" variant="default" defaultChecked /> <Checkbox id="primary" label="Primary" variant="primary" defaultChecked /> <Checkbox id="secondary" label="Secondary" variant="secondary" defaultChecked /> <Checkbox id="info" label="Info" variant="info" defaultChecked /> <Checkbox id="success" label="Success" variant="success" defaultChecked /> <Checkbox id="warning" label="Warning" variant="warning" defaultChecked /> <Checkbox id="error" label="Error" variant="error" defaultChecked /> </> );}<script setup lang="ts">import { Checkbox } from "@/components/starwind/checkbox";</script>
<template> <Checkbox id="default" label="Default" variant="default" defaultChecked /> <Checkbox id="primary" label="Primary" variant="primary" defaultChecked /> <Checkbox id="secondary" label="Secondary" variant="secondary" defaultChecked /> <Checkbox id="info" label="Info" variant="info" defaultChecked /> <Checkbox id="success" label="Success" variant="success" defaultChecked /> <Checkbox id="warning" label="Warning" variant="warning" defaultChecked /> <Checkbox id="error" label="Error" variant="error" defaultChecked /></template><script lang="ts"> import { Checkbox } from "@/components/starwind/checkbox";</script>
<Checkbox id="default" label="Default" variant="default" defaultChecked /><Checkbox id="primary" label="Primary" variant="primary" defaultChecked /><Checkbox id="secondary" label="Secondary" variant="secondary" defaultChecked /><Checkbox id="info" label="Info" variant="info" defaultChecked /><Checkbox id="success" label="Success" variant="success" defaultChecked /><Checkbox id="warning" label="Warning" variant="warning" defaultChecked /><Checkbox id="error" label="Error" variant="error" defaultChecked />Sizes
---import { Checkbox } from "@/components/starwind/checkbox";---
<Checkbox id="small" label="Small" size="sm" /><Checkbox id="medium" label="Medium" size="md" /><Checkbox id="large" label="Large" size="lg" />import { Checkbox } from "@/components/starwind/checkbox";
export function Example() { return ( <> <Checkbox id="small" label="Small" size="sm" /> <Checkbox id="medium" label="Medium" size="md" /> <Checkbox id="large" label="Large" size="lg" /> </> );}<script setup lang="ts">import { Checkbox } from "@/components/starwind/checkbox";</script>
<template> <Checkbox id="small" label="Small" size="sm" /> <Checkbox id="medium" label="Medium" size="md" /> <Checkbox id="large" label="Large" size="lg" /></template><script lang="ts"> import { Checkbox } from "@/components/starwind/checkbox";</script>
<Checkbox id="small" label="Small" size="sm" /><Checkbox id="medium" label="Medium" size="md" /><Checkbox id="large" label="Large" size="lg" />Disabled
---import { Checkbox } from "@/components/starwind/checkbox";---
<Checkbox id="disabled" label="Disabled" disabled /><Checkbox id="disabled-checked" label="Disabled Checked" disabled defaultChecked />import { Checkbox } from "@/components/starwind/checkbox";
export function Example() { return ( <> <Checkbox id="disabled" label="Disabled" disabled /> <Checkbox id="disabled-checked" label="Disabled Checked" disabled defaultChecked /> </> );}<script setup lang="ts">import { Checkbox } from "@/components/starwind/checkbox";</script>
<template> <Checkbox id="disabled" label="Disabled" disabled /> <Checkbox id="disabled-checked" label="Disabled Checked" disabled defaultChecked /></template><script lang="ts"> import { Checkbox } from "@/components/starwind/checkbox";</script>
<Checkbox id="disabled" label="Disabled" disabled /><Checkbox id="disabled-checked" label="Disabled Checked" disabled defaultChecked />API Reference
Styled Component API
These props are added or materially changed by the installed styled component. Standard HTML attributes remain available through the inherited interfaces noted below. Expand a prop to see named type definitions and framework-specific imports. Follow the Primitive and Runtime links for lower-level behavior props.
Checkbox
Inherits span attributes. Omits `defaultChecked`, `id`, and `onChange`.
Contains the following additional props:
Prop Type Default Toggle details
defaultChecked boolean —
- Description
- Sets the initial checked state when the choice is uncontrolled.
- Classification
- Primitive override
- Primitive prop
- checkbox.Root.defaultChecked
label string —
- Description
- Provides accessible text for the component.
- Classification
- Wrapper prop
size "sm" | "md" | "lg" "md"
- Description
- Selects the component's visual size.
- Classification
- Styled variant
variant "default" | "primary" | "secondary" | "info" | "success" | "warning" | "error" "default"
- Description
- Selects the component's visual variant.
- Classification
- Styled variant
Primitive And Runtime API
Use these references when you need the lower-level behavior APIs behind Checkbox.
Primitive API
Runtime API
- Checkbox primitive
createCheckboxfrom@starwind-ui/runtime/checkbox
Changelog
View version history v2.1.1 12 releases
v2.1.1
- Checkbox now limits its transition to visual colors and opacity, so layout changes do not animate the control.
- In Vue, this component now needs Vue 3.5.21 or newer.
- Internal code cleanup, such as unused code and import order. This cleanup does not change behavior.
v2.1.0
- In Svelte, a defined
checkedthat you pass when Checkbox mounts now stays under your control, as in React and Vue. To change it, usebind:or update your state in the change callback. A form reset keeps it. If you passundefinedat mount, Checkbox keeps its own state. - In Vue, a Boolean prop that you leave out, such as
defaultChecked, no longer becomesfalse. The default of the underlying component applies. - Inside a
Fieldin Astro, Checkbox now clears when the form resets. Before, it stayed checked.
v2.0.3
- When you set
indeterminate, the box now fills with the variant color and shows a minus icon in every variant. The error border still shows when the field is invalid. Before, the default variant looked unchecked in light mode, and the other variants showed only a faint check. - Checkbox now gets its name from a
<label for>that points at itsid. Before, screen readers read it with no name. - In Astro, a required Checkbox in a plain HTML form now shows the browser message and gets focus. Before, the form did not submit, and no message showed.
- When the browser flags a required Checkbox as invalid, focus now goes to the checkbox that the user sees.
v2.0.2
- In React, the initial native checkbox value now matches the checked value supplied by your app.
- Vue Checkbox keeps its previous checked value when a change is canceled.
- Fixed React and Vue form resets restoring the wrong value after a control is recreated. Resets now use its original default.
- Reduced the JavaScript loaded by Checkbox when it is used without Field.
v2.0.1
- In React, you can cancel a change before it applies. The component then keeps its previous state, and it shows only the changes that apply.
v2.0.0
- Checkbox now gets its behavior from Starwind Runtime. Runtime handles the checked state, the native form value, and the checked-change events.
- See the Checkbox Primitive for the unstyled parts and the behavior API.
v1.4.3
- The Tailwind variants now live in their own
variants.tsfile in the component folder.
v1.4.1
- add
aria-invalidstyling
v1.4.0
- style and focus state updates
v1.3.0
- Add a
data-slotattribute to all components to enable global styling updates
v1.2.0
- No longer require an “id” prop
- Adjust component to use type
VariantPropsfromtailwind-variants. This provides greater type safety and cleans up component frontmatter.
v1.1.0
tailwind-variantsnow implemented. This usestailwind-mergeunder the hood to merge Tailwind classes without style conflicts, allowing you to override any existing classes using the “class” prop.