Checkbox

free

Checkbox handles independent choices in settings, filters, and multi-select flows.

Notification channels

Select the channels that should receive weekly account updates.

import { useState } from 'react';
import Checkbox from '@/components/ui/checkbox';
import type { CheckboxGroupValue } from '@/components/ui/checkbox';

Installation

Add this component with the NateUI CLI.

npx nateui@latest add Checkbox

Examples

Basic

import Checkbox from '@/components/ui/checkbox';

export default function BasicDemo() {
  return (

Group

import { useState } from 'react';
import Checkbox from '@/components/ui/checkbox';
import type { CheckboxGroupValue } from '@/components/ui/checkbox';

Vertical

import Checkbox from '@/components/ui/checkbox';

export default function VerticalDemo() {
  return (

States

import Checkbox from '@/components/ui/checkbox';

export default function StatesDemo() {
  return (

Indeterminate

import { useState } from 'react';
import Checkbox from '@/components/ui/checkbox';
import type { CheckboxGroupValue } from '@/components/ui/checkbox';

Custom Color

import Checkbox from '@/components/ui/checkbox';

export default function CustomColorDemo() {
  return (

Controlled

import { useState } from 'react';
import Button from '@/components/ui/button';
import Checkbox from '@/components/ui/checkbox';

API

Checkbox exposes a root checkbox input and a compound Checkbox.Group for multiple selections.

Checkbox

Checkbox accepts the props below plus native props for the underlying input.

PropDescriptionTypeDefault
checkedControls the checked state.boolean-
checkboxClassClass names applied to the checkbox control for color or local styling.string-
childrenLabel content rendered beside the checkbox control.ReactNode-
classNameClass names applied to the root label.string-
defaultCheckedInitial checked state for uncontrolled usage.boolean-
disabledPrevents pointer interaction and applies disabled styling.boolean-
indeterminateRenders the indeterminate mark when the checkbox is checked.booleanfalse
labelRefRef forwarded to the root label element.Ref<HTMLLabelElement>-
nameName passed to the input, or inherited from Checkbox.Group.stringGroup name
onChangeCalled with the next checked state and the input change event.CheckboxChangeHandler-
readOnlyPrevents the component from changing its internal state.boolean-
refRef forwarded to the underlying checkbox input.Ref<HTMLInputElement>-
valueValue used by Checkbox.Group and passed through to the input.CheckboxValue-
...nativeInputPropsNative props for the underlying checkbox input, except onChange.NativeCheckboxInputProps-

Checkbox.Group

Checkbox.Group accepts the props below plus native props for the root div.

PropDescriptionTypeDefault
checkboxClassClass names shared by every checkbox control inside the group.string-
childrenCheckbox items rendered inside the group.ReactNode-
classNameClass names applied to the group root.string-
nameName shared by checkbox inputs inside the group.string-
onChangeCalled with the next selected value array and the source event.CheckboxGroupChangeHandler-
refRef forwarded to the group root.Ref<HTMLDivElement>-
valueControlled selected values for the group.CheckboxGroupValue-
verticalStacks group items vertically.booleanfalse
...nativeDivPropsNative props for the group root div, except onChange.NativeCheckboxGroupDivProps-

Types

type CheckboxValue = string | number | boolean;
type CheckboxGroupValue = string[];
type CheckboxChangeHandler = (
  checked: boolean,
  event: ChangeEvent<HTMLInputElement>,
) => void;
type CheckboxGroupChangeHandler = (
  value: CheckboxGroupValue,
  event: SyntheticEvent,
) => void;
type NativeCheckboxInputProps = Omit<
  ComponentPropsWithRef<'input'>,
  'onChange'
>;
type NativeCheckboxGroupDivProps = Omit<
  ComponentPropsWithRef<'div'>,
  'onChange'
>;