---
title: "Checkbox Group · Ark UI — StyleX Blocks"
description: "A set of checkboxes sharing one value array, stacked or in a row, with an optional select-all parent."
url: "https://stylexblocks.com/components/ark-ui/checkbox-group/"
agent:
  instructions: "Use this search API to find relevant components and blocks across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://stylexblocks.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Checkbox Group

A set of checkboxes sharing one value array, stacked or in a row, with an optional select-all parent.

- Behavior engine: Ark UI
- Also available for: [Base UI](https://stylexblocks.com/components/base-ui/checkbox-group.md), [UI SDK](https://stylexblocks.com/components/ui-sdk/checkbox-group.md)
- Category: Form
- Variants: outline, solid, subtle
- Sizes: xs, sm, md, lg
- HTML page: https://stylexblocks.com/components/ark-ui/checkbox-group/

## Install

Configure the project once (sets the behavior engine and import aliases):

```sh
npx stylexblocks init
```

Then add the item as source you own:

```sh
npx stylexblocks add checkbox-group
```

Equivalent: `npx shadcn add @stylexblocks/checkbox-group`. Registry item JSON: https://stylexblocks.com/r/ark-ui/checkbox-group.json

## Usage

```tsx
import { CheckboxGroup } from "#components/ui/ark-ui/checkbox-group.tsx";
import { indigoPalette } from "@stylexblocks/ui/themes/palettes.ts";

export function Example() {
  return (
    // variant/size/orientation resolve once on Root; every item inherits them.
    // The group owns the value array; each Item names its own value.
    <CheckboxGroup.Root defaultValue={["email"]} variant="solid" size="md" palette={indigoPalette}>
      <CheckboxGroup.Item value="email">
        <CheckboxGroup.ItemControl />
        <CheckboxGroup.ItemLabel>Email</CheckboxGroup.ItemLabel>
        <CheckboxGroup.ItemHiddenInput />
      </CheckboxGroup.Item>
      <CheckboxGroup.Item value="sms">
        <CheckboxGroup.ItemControl />
        <CheckboxGroup.ItemLabel>SMS</CheckboxGroup.ItemLabel>
        <CheckboxGroup.ItemHiddenInput />
      </CheckboxGroup.Item>
    </CheckboxGroup.Root>
  );
}

// controlled: <CheckboxGroup.Root value={value} onValueChange={setValue}>
```

## Examples

### Horizontal

orientation="horizontal" lays the items out in a wrapping row; the gap follows the size.

```tsx
import { CheckboxGroup } from "#components/ui/ark-ui/checkbox-group.tsx";

<CheckboxGroup.Root orientation="horizontal" defaultValue={["email"]}>
  {/* …items */}
</CheckboxGroup.Root>
```

### Select all

Give Root allValues and mark one Item parent: it checks when every item is selected, turns indeterminate on a partial selection, and toggles them all.

```tsx
import { CheckboxGroup } from "#components/ui/ark-ui/checkbox-group.tsx";

const channels = ["email", "sms", "push"];

export function Example() {
  return (
    // allValues lets the parent item compute checked / indeterminate
    <CheckboxGroup.Root defaultValue={["email"]} allValues={channels}>
      <CheckboxGroup.Item parent>
        <CheckboxGroup.ItemControl />
        <CheckboxGroup.ItemLabel>All channels</CheckboxGroup.ItemLabel>
        <CheckboxGroup.ItemHiddenInput />
      </CheckboxGroup.Item>
      {channels.map((value) => (
        <CheckboxGroup.Item key={value} value={value}>
          <CheckboxGroup.ItemControl />
          <CheckboxGroup.ItemLabel>{value}</CheckboxGroup.ItemLabel>
          <CheckboxGroup.ItemHiddenInput />
        </CheckboxGroup.Item>
      ))}
    </CheckboxGroup.Root>
  );
}
```

## Source

`components/ui/ark-ui/checkbox-group.tsx`

```tsx
import * as stylex from "@stylexjs/stylex";
import { createContext, useContext } from "react";
import {
  Checkbox as ArkCheckbox,
  useCheckboxContext,
  useCheckboxGroupContext,
} from "@ark-ui/react/checkbox";
import { createSlotRecipeContext } from "#lib/ark-ui/create-slot-recipe-context.tsx";
import {
  defineSlotRecipe,
  fromMap,
  resolveSlotStyles,
} from "#lib/recipe-props.ts";
import { colorPalette } from '@stylexblocks/ui/color-palette.stylex.ts'
import { colors } from '@stylexblocks/ui/tokens/colors.stylex.ts'
import { fontSizes } from '@stylexblocks/ui/tokens/font-sizes.stylex.ts'
import { fontWeights } from '@stylexblocks/ui/tokens/font-weights.stylex.ts'
import { lineHeights } from '@stylexblocks/ui/tokens/line-heights.stylex.ts'
import { semanticColors } from '@stylexblocks/ui/semantic-tokens/colors.stylex.ts'
import { semanticRadii } from '@stylexblocks/ui/semantic-tokens/radii.stylex.ts'
import { sizes } from '@stylexblocks/ui/tokens/sizes.stylex.ts'
import { spacing } from '@stylexblocks/ui/tokens/spacing.stylex.ts'

const checkboxRoot = stylex.create({
  base: {
    display: 'inline-flex',
    gap: spacing._2,
    alignItems: 'center',
    verticalAlign: 'top',
    position: 'relative',
  },
})

const checkboxRootSizes = stylex.create({
  xs: {
    gap: spacing._1_5,
  },
  sm: {
    gap: spacing._2,
  },
  md: {
    gap: spacing._2_5,
  },
  lg: {
    gap: spacing._3,
  },
})

const checkboxControl = stylex.create({
  base: {
    display: 'inline-flex',
    alignItems: 'center',
    justifyContent: 'center',
    flexShrink: 0,
    color: colors.white,
    borderWidth: '1px',
    borderColor: {
      default: 'transparent',
      ':is([data-invalid], [aria-invalid="true"])': semanticColors.borderError,
    },
    borderRadius: semanticRadii.control,
    outlineWidth: {
      default: null,
      ':focus-visible': '1px',
    },
    outlineOffset: {
      default: null,
      ':focus-visible': '2px',
    },
    outlineStyle: {
      default: null,
      ':focus-visible': 'solid',
    },
    outlineColor: {
      default: null,
      ':focus-visible': colorPalette.focusRing,
    },
    opacity: {
      default: null,
      ':is(:disabled, [disabled], [data-disabled])': 0.5,
    },
  },
})

const checkboxControlSizes = stylex.create({
  xs: {
    width: sizes._3,
    height: sizes._3,
  },
  sm: {
    width: sizes._3_5,
    height: sizes._3_5,
  },
  md: {
    width: sizes._4,
    height: sizes._4,
    padding: spacing._0_5,
  },
  lg: {
    width: sizes._5,
    height: sizes._5,
    padding: spacing._0_5,
  },
})

const checkboxControlVariants = stylex.create({
  outline: {
    borderColor: {
      default: semanticColors.borderEmphasized,
      ':is([data-invalid], [aria-invalid="true"])': semanticColors.borderError,
    },
  },
  solid: {
    borderColor: {
      default: semanticColors.borderEmphasized,
      ':is([data-invalid], [aria-invalid="true"])': semanticColors.borderError,
    },
  },
  subtle: {
    backgroundColor: colorPalette.muted,
    borderColor: {
      default: colorPalette.emphasized,
      ':is([data-invalid], [aria-invalid="true"])': semanticColors.borderError,
    },
  },
})

const checkboxLabel = stylex.create({
  base: {
    fontWeight: fontWeights.medium,
    userSelect: 'none',
    opacity: {
      default: null,
      ':is(:disabled, [disabled], [data-disabled])': 0.5,
    },
  },
})

const checkboxLabelSizes = stylex.create({
  xs: {
    fontSize: fontSizes.xs,
    lineHeight: lineHeights.xs,
  },
  sm: {
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
  },
  md: {
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
  },
  lg: {
    fontSize: fontSizes.md,
    lineHeight: lineHeights.md,
  },
})

export type CheckboxSize = keyof typeof checkboxRootSizes

export type CheckboxVariant = keyof typeof checkboxControlVariants

// The group adds only layout; every item wears the checkbox recipe, so a
// grouped checkbox looks exactly like a lone one.
const checkboxGroupLayout = stylex.create({
  base: {
    display: "flex",
  },
});

const checkboxGroupOrientations = stylex.create({
  vertical: {
    flexDirection: "column",
    alignItems: "flex-start",
  },
  horizontal: {
    flexDirection: "row",
    flexWrap: "wrap",
    alignItems: "center",
  },
});

const checkboxGroupSizes = stylex.create({
  xs: { rowGap: spacing._1_5, columnGap: spacing._3 },
  sm: { rowGap: spacing._2, columnGap: spacing._4 },
  md: { rowGap: spacing._2_5, columnGap: spacing._5 },
  lg: { rowGap: spacing._3, columnGap: spacing._6 },
});

const checkboxGroupRecipe = defineSlotRecipe({
  slots: {
    root: {
      styles: checkboxGroupLayout,
      sizes: checkboxGroupSizes,
      orientations: checkboxGroupOrientations,
    },
    item: { styles: checkboxRoot, sizes: checkboxRootSizes },
    control: {
      styles: checkboxControl,
      sizes: checkboxControlSizes,
      variants: checkboxControlVariants,
    },
    label: { styles: checkboxLabel, sizes: checkboxLabelSizes },
  },
  defaultVariants: { variant: "solid", size: "md", orientation: "vertical" },
});

// Checked (and indeterminate) chrome keyed off `data-checked`, which
// ControlNode copies from the machine.
const checkboxChecked = stylex.create({
  outline: {
    color: { default: null, ":is([data-checked])": colorPalette.fg },
    borderColor: { default: null, ":is([data-checked])": colorPalette.solid },
  },
  solid: {
    backgroundColor: { default: null, ":is([data-checked])": colorPalette.solid },
    borderColor: { default: null, ":is([data-checked])": colorPalette.solid },
    color: { default: null, ":is([data-checked])": colorPalette.contrast },
  },
  subtle: {
    color: { default: null, ":is([data-checked])": colorPalette.fg },
  },
});

const chrome = stylex.create({
  cursorPointer: { cursor: "pointer" },
  iconFill: { width: "100%", height: "100%" },
});

function CheckIcon() {
  return (
    <svg viewBox="0 0 12 12" fill="none" aria-hidden="true" {...stylex.props(chrome.iconFill)}>
      <path
        d="M2.5 6.4 5 8.9l4.5-5.4"
        stroke="currentColor"
        strokeWidth="2"
        strokeLinecap="round"
        strokeLinejoin="round"
      />
    </svg>
  );
}

function MinusIcon() {
  return (
    <svg viewBox="0 0 12 12" fill="none" aria-hidden="true" {...stylex.props(chrome.iconFill)}>
      <path d="M3 6h6" stroke="currentColor" strokeWidth="2" strokeLinecap="round" />
    </svg>
  );
}

const AllValuesContext = createContext<readonly string[] | undefined>(undefined);

function RootNode({
  allValues,
  ...props
}: React.ComponentProps<typeof ArkCheckbox.Group> & {
  /** Every item value — required for a `parent` item to compute its state. */
  allValues?: readonly string[];
}) {
  return (
    <AllValuesContext.Provider value={allValues}>
      <ArkCheckbox.Group {...props} />
    </AllValuesContext.Provider>
  );
}

function ItemNode({
  parent,
  ...props
}: React.ComponentProps<typeof ArkCheckbox.Root> & {
  /**
   * Makes this item the group's "select all" checkbox: checked when every
   * value in Root's `allValues` is selected, indeterminate when some are,
   * and toggles all of them at once.
   */
  parent?: boolean;
}) {
  const group = useCheckboxGroupContext();
  const allValues = useContext(AllValuesContext);
  if (!parent || !group || !allValues) return <ArkCheckbox.Root {...props} />;
  const selected = allValues.filter((value) => group.isChecked(value)).length;
  const all = selected === allValues.length;
  return (
    <ArkCheckbox.Root
      data-parent=""
      {...props}
      checked={all ? true : selected > 0 ? "indeterminate" : false}
      onCheckedChange={(details) => {
        const others = group.value.filter((value) => !allValues.includes(value));
        group.setValue(all ? others : [...others, ...allValues]);
        props.onCheckedChange?.(details);
      }}
    />
  );
}

function ControlNode({
  children,
  ...props
}: React.ComponentProps<typeof ArkCheckbox.Control>) {
  const checkbox = useCheckboxContext();
  const on = checkbox.checked || checkbox.indeterminate;
  return (
    <ArkCheckbox.Control {...props} data-checked={on ? "" : undefined}>
      {children ?? <Indicator />}
    </ArkCheckbox.Control>
  );
}

export interface CheckboxGroupIndicatorProps {
  children?: React.ReactNode;
}

/** Renders while checked (check icon) or indeterminate (minus icon). */
function Indicator({ children }: CheckboxGroupIndicatorProps) {
  const checkbox = useCheckboxContext();
  if (checkbox.indeterminate) return children ?? <MinusIcon />;
  if (!checkbox.checked) return null;
  return children ?? <CheckIcon />;
}

const { withProvider, withContext } = createSlotRecipeContext(checkboxGroupRecipe);

/**
 * Checkbox Group — Ark UI's `Checkbox.Group` holding checkboxes that wear the
 * checkbox slot recipe. `<CheckboxGroup.Root variant size orientation>`
 * resolves the recipe once; every item inherits it. The group owns the
 * selected `value` array; each Item names its own `value`. Give Root
 * `allValues` and mark one Item `parent` for a "select all" checkbox that
 * turns indeterminate on a partial selection.
 */
export const CheckboxGroup = {
  Root: withProvider(RootNode, "root", "CheckboxGroupRoot"),
  Item: withContext(
    ItemNode,
    (v) => [...resolveSlotStyles(checkboxGroupRecipe.slots.item, v), chrome.cursorPointer],
    "CheckboxGroupItem",
  ),
  ItemControl: withContext(
    ControlNode,
    (v) => [
      ...resolveSlotStyles(checkboxGroupRecipe.slots.control, v),
      fromMap(checkboxChecked, v.variant),
    ],
    "CheckboxGroupItemControl",
  ),
  ItemIndicator: Indicator,
  ItemLabel: withContext(ArkCheckbox.Label, "label", "CheckboxGroupItemLabel"),
  ItemHiddenInput: ArkCheckbox.HiddenInput,
};

export type CheckboxGroupRootProps = React.ComponentProps<typeof CheckboxGroup.Root>;
export type CheckboxGroupItemProps = React.ComponentProps<typeof CheckboxGroup.Item>;
export type CheckboxGroupItemControlProps = React.ComponentProps<typeof CheckboxGroup.ItemControl>;
export type CheckboxGroupItemLabelProps = React.ComponentProps<typeof CheckboxGroup.ItemLabel>;
```
