Unkey
Components

Checkbox

A versatile checkbox component with multiple variants, states, and sizes

Checkbox

A versatile checkbox component that supports various styles, states, and interactive features. Checkbox is built with accessibility in mind and provides consistent interaction patterns across all variants.

Each checkbox can be customized with different variants, colors, and sizes, making it adaptable to any UI context. All checkboxes include proper focus states and keyboard interactions.

Basic Variants

Checkbox comes in three basic variants that serve different UI purposes:

Primary

The default checkbox style with a solid background when checked. Use for primary selection actions.

Light

Dark

Outline

Checkbox with transparent background and visible border when checked. Ideal for secondary selection actions that don't require as much visual emphasis.

Light

Dark

Ghost

Checkbox with no background when unchecked and subtle hover states. Perfect for tertiary selection actions or when space is limited.

Light

Dark

Color Variants

Each checkbox variant can be combined with different color schemes to convey the nature of the selection:

Danger - Primary

Light

Dark

Danger - Outline

Light

Dark

Danger - Ghost

Light

Dark

Warning - Primary

Light

Dark

Warning - Outline

Light

Dark

Warning - Ghost

Light

Dark

Success - Primary

Light

Dark

Success - Outline

Light

Dark

Success - Ghost

Light

Dark

Info - Primary

Light

Dark

Info - Outline

Light

Dark

Info - Ghost

Light

Dark

Size Variants

All checkbox variants and color schemes can be combined with different sizes to fit various UI contexts.

Light

Dark

With Labels

Checkbox components can be combined with labels for better user experience.

Light

Dark

Checkbox Group Example

Checkboxes can be grouped together for related selection options.

Notification Preferences

Additional Features

The Checkbox component includes some additional features not shown in all examples above:

Legacy Variant Support

For backward compatibility, the component supports legacy variants:

  • default will be mapped to primary variant
  • destructive will be mapped to primary variant with danger color

Customizing Indicator

The Checkbox uses the Check component from @unkey/icons as the default indicator when checked. The icon size adapts automatically to the size of the checkbox.

Props

The Checkbox component accepts all standard HTML input attributes plus the following:

PropTypeDefault
variant
"default" | "primary" | "outline" | "ghost"
"primary"
color
"default" | "success" | "warning" | "danger" | "info"
"default"
size
"sm" | "md" | "lg" | "xlg"
"md"
checked
boolean
-
defaultChecked
boolean
-
disabled
boolean
-
required
boolean
-
name
string
-
value
string
-
onCheckedChange
(checked: boolean) => void
-

Implementation Details

The Checkbox component is built with Radix UI's @radix-ui/react-checkbox primitive for accessibility and proper keyboard navigation. It includes:

  • Custom styling for all states: unchecked, checked, disabled, and focus
  • Support for different variants through CSS variable variants
  • Automatic icon size adjustment based on checkbox size
  • Proper ARIA attributes for screen readers

Usage Guidelines

When using the Checkbox component:

  • Semantic meaning: Choose appropriate colors to match the semantic meaning of your checkboxes

    • Use default for standard selections without specific connotations
    • Use success for positive or confirming selections
    • Use warning for cautionary selections that require attention
    • Use danger for critical or potentially destructive selections
    • Use info for informational or neutral selections
  • Accessibility:

    • Always pair checkboxes with visible labels that clearly describe the selection
    • Ensure sufficient color contrast between the checkbox and its background
    • Group related checkboxes together with a descriptive group label
    • Test keyboard navigation (Tab to focus, Space to toggle)
  • Interaction design:

    • Use appropriate sizing based on the context and target devices (consider touch targets for mobile)
    • Maintain consistent spacing between checkboxes in a group
    • Provide clear visual feedback for all states (hover, focus, checked, disabled)
  • Content guidelines:

    • Write clear, concise labels that describe the option being selected
    • Use sentence case for checkbox labels
    • For groups of checkboxes, use a descriptive heading that explains the purpose of the group
  • Form design:

    • Consider using the required attribute when a checkbox must be checked to proceed
    • For lengthy terms and conditions, consider linking to the full text rather than showing it all
    • For mutually exclusive options, consider using radio buttons instead
  • Responsive design:

    • Ensure checkboxes and their labels are properly sized and spaced on all devices
    • Consider stacking checkboxes vertically on smaller screens for better touch targets