---
title: "Checkbox · UI SDK — StyleX Blocks"
description: "Binary selection controls with outline, solid, and subtle boxes and a paired label."
url: "https://stylexblocks.com/components/ui-sdk/checkbox/"
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

Binary selection controls with outline, solid, and subtle boxes and a paired label.

- Behavior engine: UI SDK
- Also available for: [Ark UI](https://stylexblocks.com/components/ark-ui/checkbox.md), [Base UI](https://stylexblocks.com/components/base-ui/checkbox.md)
- Category: Form
- Variants: outline, solid, subtle
- Sizes: xs, sm, md, lg
- Used in blocks: [Basic Login](https://stylexblocks.com/block/ui-sdk/basic-login.md), [Checkout Form](https://stylexblocks.com/block/ui-sdk/checkout-form.md), [Checkout Wizard](https://stylexblocks.com/block/ui-sdk/checkout-wizard.md), [Contact Form](https://stylexblocks.com/block/ui-sdk/contact-form.md), [Course Detail](https://stylexblocks.com/block/ui-sdk/course-detail.md), [Documentation Technical](https://stylexblocks.com/block/ui-sdk/documentation-technical.md), [Filterable Table](https://stylexblocks.com/block/ui-sdk/filterable-table.md), [Two-Column Form](https://stylexblocks.com/block/ui-sdk/form-two-column.md), [Form Wizard](https://stylexblocks.com/block/ui-sdk/form-wizard.md), [Vertical Wizard](https://stylexblocks.com/block/ui-sdk/form-wizard-vertical.md), [Grouped Table](https://stylexblocks.com/block/ui-sdk/grouped-table.md), [Inbox Table](https://stylexblocks.com/block/ui-sdk/inbox-table.md), [Incident Console](https://stylexblocks.com/block/ui-sdk/incident-console.md), [Kanban Board](https://stylexblocks.com/block/ui-sdk/kanban-board.md), [Login Card](https://stylexblocks.com/block/ui-sdk/login-card.md), [Login Split](https://stylexblocks.com/block/ui-sdk/login-split.md), [Page Editor](https://stylexblocks.com/block/ui-sdk/page-editor.md), [Searchable Table](https://stylexblocks.com/block/ui-sdk/searchable-table.md), [Settings Form](https://stylexblocks.com/block/ui-sdk/settings-form.md), [Simple Table](https://stylexblocks.com/block/ui-sdk/simple-table.md), [Theme Showcase](https://stylexblocks.com/block/ui-sdk/theme-showcase.md), [Tree Table](https://stylexblocks.com/block/ui-sdk/tree-table.md), [Work Item Detail](https://stylexblocks.com/block/ui-sdk/work-item-detail.md)
- HTML page: https://stylexblocks.com/components/ui-sdk/checkbox/

## Install

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

```sh
npx stylexblocks init --style ui-sdk
```

Then add the item as source you own:

```sh
npx stylexblocks add checkbox
```

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

## Usage

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

export function Example() {
  return (
    // Root is the label wrapper; Control is UI SDK's Checkbox (a checkbox
    // button plus a hidden native input) and takes the checked props
    <Checkbox.Root variant="solid" size="md" palette={indigoPalette}>
      <Checkbox.Control defaultChecked />
      <Checkbox.Label>Email notifications</Checkbox.Label>
    </Checkbox.Root>
  );
}

// controlled: <Checkbox.Control checked={checked} onCheckedChange={setChecked} />
// mixed: <Checkbox.Control defaultChecked="indeterminate"><Checkbox.Indicator><MinusIcon /></Checkbox.Indicator></Checkbox.Control>
```

## Source

`components/ui/ui-sdk/checkbox.tsx`

```tsx
import * as stylex from "@stylexjs/stylex";
import {
  Checkbox as UiSdkCheckbox,
  CheckboxIndicator as UiSdkCheckboxIndicator,
} from "@ui-sdk/react/checkbox";
import { mergeProps } from "@ui-sdk/react/primitive";
import { createSlotRecipeContext } from "#lib/ui-sdk/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

const checkboxRecipe = defineSlotRecipe({
  slots: {
    root: { styles: checkboxRoot, sizes: checkboxRootSizes },
    control: {
      styles: checkboxControl,
      sizes: checkboxControlSizes,
      variants: checkboxControlVariants,
    },
    label: { styles: checkboxLabel, sizes: checkboxLabelSizes },
  },
  defaultVariants: { variant: "solid", size: "md" },
});

// Checked-state chrome keyed off UI SDK's `data-checked` (and
// `data-indeterminate`, which UI SDK stamps instead of `data-checked` while
// mixed) — the generated recipe does not style the checked fill.
const checkboxChecked = stylex.create({
  outline: {
    color: { default: null, ":is([data-checked], [data-indeterminate])": colorPalette.fg },
    borderColor: {
      default: null,
      ":is([data-checked], [data-indeterminate])": colorPalette.solid,
    },
  },
  solid: {
    backgroundColor: {
      default: null,
      ":is([data-checked], [data-indeterminate])": colorPalette.solid,
    },
    borderColor: {
      default: null,
      ":is([data-checked], [data-indeterminate])": colorPalette.solid,
    },
    color: {
      default: null,
      ":is([data-checked], [data-indeterminate])": colorPalette.contrast,
    },
  },
  subtle: {
    color: { default: null, ":is([data-checked], [data-indeterminate])": colorPalette.fg },
  },
});

const chrome = stylex.create({
  cursorPointer: { cursor: "pointer" },
  iconFill: { width: "100%", height: "100%" },
  indicator: {
    display: "inline-flex",
    width: "100%",
    height: "100%",
    alignItems: "center",
    justifyContent: "center",
  },
});

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 ControlNode({
  children,
  ...props
}: React.ComponentProps<typeof UiSdkCheckbox>) {
  return <UiSdkCheckbox {...props}>{children ?? <Indicator />}</UiSdkCheckbox>;
}

export type CheckboxIndicatorProps = React.ComponentProps<typeof UiSdkCheckboxIndicator>;

/** Mounted only while checked or mixed — defaults to the check icon. */
function Indicator({ children, ...props }: CheckboxIndicatorProps) {
  return (
    <UiSdkCheckboxIndicator {...mergeProps(props, stylex.props(chrome.indicator))}>
      {children ?? <CheckIcon />}
    </UiSdkCheckboxIndicator>
  );
}

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

/**
 * Checkbox — UI SDK's checkbox wearing the checkbox slot recipe. The Root
 * label resolves variant and size once; Control (UI SDK's Checkbox, a
 * `role="checkbox"` button plus a hidden native input for forms) and Label
 * inherit them through context. Control takes the checked props
 * (`defaultChecked`, `checked`/`onCheckedChange`, `"indeterminate"`).
 * Checked chrome targets UI SDK's `data-checked` / `data-indeterminate`.
 */
export const Checkbox = {
  Root: withProvider(
    "label",
    (v) => [...resolveSlotStyles(checkboxRecipe.slots.root, v), chrome.cursorPointer],
    "CheckboxRoot",
  ),
  Control: withContext(
    ControlNode,
    (v) => [
      ...resolveSlotStyles(checkboxRecipe.slots.control, v),
      fromMap(checkboxChecked, v.variant),
    ],
    "CheckboxControl",
  ),
  Indicator,
  Label: withContext("span", "label", "CheckboxLabel"),
};

export type CheckboxRootProps = React.ComponentProps<typeof Checkbox.Root>;
export type CheckboxControlProps = React.ComponentProps<typeof Checkbox.Control>;
export type CheckboxLabelProps = React.ComponentProps<typeof Checkbox.Label>;
```
