Skip to main content

Checkbox

Checkbox is a toggle checkbox component with size variants, custom styling, and optional inline labels.

Import

import { Checkbox } from "@tosui/react";

Basic Usage

<Checkbox label="Accept terms and conditions" />

Without Label

<Checkbox aria-label="Toggle option" />

Sizes

<VStack gap={4} align="flex-start">
<Checkbox size="sm" label="Small checkbox" />
<Checkbox size="md" label="Medium checkbox (default)" />
<Checkbox size="lg" label="Large checkbox" />
</VStack>

States

<VStack gap={4} align="flex-start">
<Checkbox label="Unchecked" />
<Checkbox label="Checked" defaultChecked />
<Checkbox label="Disabled" disabled />
<Checkbox label="Disabled checked" disabled defaultChecked />
<Checkbox label="Invalid" isInvalid />
</VStack>

Controlled

Use isChecked and onChange for controlled mode.

function ControlledCheckbox() {
const [checked, setChecked] = useState(false);

return (
<Checkbox
label="Controlled checkbox"
isChecked={checked}
onChange={(e) => setChecked(e.target.checked)}
/>
);
}

Checkbox Group

Group checkboxes for multiple selections.

<VStack gap={2} align="flex-start">
<Box fontWeight="medium">Select toppings:</Box>
<Checkbox label="Pepperoni" />
<Checkbox label="Mushrooms" />
<Checkbox label="Onions" />
<Checkbox label="Extra cheese" />
</VStack>

With FormField

Use with FormField for validation.

<FormField
label="Terms"
errorMessage="You must accept the terms"
isInvalid
isRequired
>
<Checkbox label="I accept the terms and conditions" />
</FormField>

Props Reference

PropTypeDefaultDescription
size"sm" | "md" | "lg""md"Checkbox size
labelstring-Optional label text
disabledbooleanfalseDisable the checkbox
isInvalidbooleanfalseShow invalid state
isCheckedboolean-Controlled checked state
defaultCheckedboolean-Initial checked state (uncontrolled)
onChange(e: ChangeEvent) => void-Change handler

Checkbox also accepts all native <input type="checkbox"> attributes.

Accessibility

  • Uses native <input type="checkbox"> for accessibility
  • Label is associated with the input
  • Supports keyboard navigation
  • When no label is provided, use aria-label for accessibility

TypeScript

import { Checkbox, type CheckboxSize, type CheckboxProps } from "@tosui/react";