Checkbox Overview

The checkbox component allows users to select one or more options from a set of choices. It's a fundamental form control that provides clear visual feedback for user selections and supports various states including checked, unchecked, indeterminate, and disabled. The component is designed with accessibility in mind, supporting keyboard navigation, screen readers, and proper form integration.

When to Use

Use checkboxes when:

  • Users need to select multiple options from a list
  • Turning features or settings on/off independently
  • Accepting terms, conditions, or agreements
  • Building forms with optional or required selections
  • Creating filter interfaces with multiple criteria
  • Allowing bulk selection operations

Don't use checkboxes for:

  • Single-choice selection (use radio buttons instead)
  • Simple yes/no questions (consider toggle switches)
  • Navigation or action triggers (use buttons)
  • Displaying status without user interaction (use status indicators)
Design system docs Examples Basic Usage

Simple checkboxes for individual selections with clear labels:

Sizes & Scaling

Choose checkbox sizes based on your layout density and visual hierarchy:

Size variations
States & Feedback

Checkboxes support various states to communicate different conditions to users:

Interactive states
Validation states
Label Positioning & Descriptions

Flexible label and description placement for different layout needs:

Label positioning
Description placement
Checkbox Groups

Use input groups to organize related checkboxes with shared labels and validation:

Settings preferences
Form validation example
Background & Border Variants

Special styling options for use on colored backgrounds or specific visual emphasis:

Background variant
Border emphasis
Real-World Patterns User Preferences Form
Account Preferences Save Preferences Cancel
Shopping Cart Features
Order Options
Total: $127.97 Proceed to Checkout
Multi-step Form with Validation
Account Setup - Step 2 of 3 Previous Step Continue
Accessibility & Keyboard Navigation

The checkbox component is designed with accessibility as a core principle:

Keyboard Support
  • Space: Toggle checkbox state
  • Enter: Alternative toggle (custom enhancement)
  • Tab: Navigate between checkboxes
  • Shift + Tab: Navigate backwards
Screen Reader Support
  • Proper ARIA labels and descriptions
  • State announcements (checked, unchecked, indeterminate)
  • Form association and validation messages
  • Group labeling for related checkboxes
Focus Management
  • Clear focus indicators
  • Logical tab order
  • Programmatic focus control
Accessibility Examples
Best Practices Form Integration
  • Always provide clear, descriptive labels
  • Use descriptions for additional context
  • Group related checkboxes with dap-ds-input-group
  • Implement proper validation feedback
  • Consider the indeterminate state for parent-child relationships
Visual Design
  • Maintain consistent sizing within forms
  • Use background variants on colored surfaces
  • Consider border emphasis for important selections
  • Provide sufficient color contrast
  • Test with different themes and accessibility settings
User Experience
  • Use progressive disclosure for complex option sets
  • Provide clear feedback for validation states
  • Consider the cognitive load of multiple options
  • Make optional vs. required selections clear
  • Test with real users and assistive technologies
Importing
import { DapDSCheckbox } from 'dap-design-system'
Importing React
import { DapDSCheckboxReact } from 'dap-design-system/react'
Tree-Shakeable Imports

For optimal bundle sizes, use the tree-shakeable import syntax:

import { DapDSCheckbox } from 'dap-design-system/components'
Attributes
PropertyTypeDefaultDescription
indeterminatebooleanfalseWhether the checkbox is indeterminate
preventDefaultbooleanfalseWhether the checkbox should prevent the default action
borderbooleanfalseThis sets up border around the checkbox, when true.
readonlybooleanfalseWhether the checkbox is readonly (cannot be changed but value is submitted with form).
type'normal', 'background''normal'The type of the checkbox
feedbackIdfeedback-${DapDSCheckbox.nextId}-${uniqueSuffix}
namestringThe name of the checkbox.
valuestringThe value of the checkbox.
checkedbooleanWhether the checkbox is checked.
labelstringThe label of the checkbox.
descriptionstringThe description of the checkbox.
disabledbooleanWhether the checkbox is disabled.
requiredbooleanWhether the checkbox is required.
size'xs', 'sm' , 'lg'The size of the checkbox. Default is 'sm'.
sizeMapstringResponsive size map (e.g. "md:lg").
labelPlacement'left', 'right'The placement of the label.
descriptionPlacement'top', 'bottom'The placement of the description.
subtlebooleanThe weight of the label.
feedbackstringThe feedback of the checkbox.
feedbackType'negative', 'positive' , 'warning'The feedback type of the checkbox.
invalidbooleanThe invalid state of the checkbox.
optionalbooleanThe optional state of the checkbox.
optionalLabelstringThe optional label of the checkbox.
Slots

No slots available.

Events
Event NameDescriptionType
dds-changeFired when the checkbox is checked or unchecked.{checked: boolean, indeterminate: boolean, value: string, disabled: boolean, readonly: boolean, type: 'checkbox' }
dds-blurEmitted when the checkbox loses focus.{void }
dds-focusEmitted when the checkbox gains focus.{void }
dds-inputEmitted when the checkbox receives input.{checked: boolean, indeterminate: boolean, value: string, disabled: boolean, readonly: boolean }
CSS Parts
Part NameDescription
baseThe main checkbox container.
labelThe label of the checkbox.
inputThe input of the checkbox.
controlThe control of the checkbox.
iconThe icon of the checkbox.
icon-baseThe base icon container.
label-containerThe label container of the checkbox.
descriptionThe description of the checkbox.
readonlyThe readonly state of the checkbox.
How to Use CSS Parts

You can style CSS parts using the ::part() pseudo-element selector:

/* Target a specific part */
.my-custom-dap-ds-checkbox::part(base) {
  /* Your custom styles */
}

/* Target multiple parts */
.my-custom-dap-ds-checkbox::part(base),
.my-custom-dap-ds-checkbox::part(label) {
  /* Shared styles */
}

Example usage:

<dap-ds-checkbox class="my-custom-dap-ds-checkbox">
  Checkbox
</dap-ds-checkbox>
.my-custom-dap-ds-checkbox::part(base) {
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

CSS parts allow you to style internal elements of the component while maintaining encapsulation. Learn more in our styling guide.

CSS Custom Properties
Property NameDescription
--dds-checkbox-sizeThe size of the checkbox. (default: var(--dds-spacing-500))
--dds-checkbox-border-widthThe border width of the checkbox. (default: var(--dds-border-width-large))
--dds-checkbox-border-radiusThe border radius of the checkbox. (default: var(--dds-radius-small))
--dds-checkbox-border-colorThe border color of the checkbox. (default: var(--dds-border-neutral-base))
--dds-checkbox-background-colorThe background color of the checkbox. (default: transparent)
--dds-checkbox-icon-colorThe color of the checkbox icon. (default: var(--dds-button-primary-icon-enabled))
--dds-checkbox-hover-border-colorThe border color when hovering over the checkbox. (default: var(--dds-border-neutral-medium))
--dds-checkbox-hover-background-colorThe background color when hovering over the checkbox. (default: var(--dds-background-neutral-medium))
--dds-checkbox-active-border-colorThe border color when the checkbox is active. (default: var(--dds-border-neutral-strong))
--dds-checkbox-active-background-colorThe background color when the checkbox is active. (default: var(--dds-background-neutral-strong))
--dds-checkbox-checked-border-colorThe border color when the checkbox is checked. (default: var(--dds-background-brand-base-inverted))
--dds-checkbox-checked-background-colorThe background color when the checkbox is checked. (default: var(--dds-background-brand-base-inverted))
--dds-checkbox-checked-hover-border-colorThe border color when hovering over a checked checkbox. (default: var(--dds-background-brand-medium-inverted))
--dds-checkbox-checked-hover-background-colorThe background color when hovering over a checked checkbox. (default: var(--dds-background-brand-medium-inverted))
--dds-checkbox-checked-active-border-colorThe border color when a checked checkbox is active. (default: var(--dds-background-brand-strong-inverted))
--dds-checkbox-checked-active-background-colorThe background color when a checked checkbox is active. (default: var(--dds-background-brand-strong-inverted))
--dds-checkbox-invalid-border-colorThe border color when the checkbox is invalid. (default: var(--dds-border-negative-base))
--dds-checkbox-invalid-background-colorThe background color when the checkbox is invalid. (default: var(--dds-background-negative-base))
--dds-checkbox-invalid-hover-border-colorThe border color when hovering over an invalid checkbox. (default: var(--dds-border-negative-medium))
--dds-checkbox-invalid-hover-background-colorThe background color when hovering over an invalid checkbox. (default: var(--dds-background-negative-medium))
--dds-checkbox-invalid-active-border-colorThe border color when an invalid checkbox is active. (default: var(--dds-border-negative-strong))
--dds-checkbox-invalid-active-background-colorThe background color when an invalid checkbox is active. (default: var(--dds-background-negative-strong))
--dds-checkbox-disabled-border-colorThe border color when the checkbox is disabled. (default: var(--dds-button-primary-background-disabled))
--dds-checkbox-disabled-background-colorThe background color when the checkbox is disabled. (default: var(--dds-button-primary-background-disabled))
--dds-checkbox-disabled-icon-colorThe color of the checkbox icon when disabled. (default: var(--dds-button-primary-icon-disabled))
--dds-checkbox-readonly-border-colorThe border color when the checkbox is readonly. (default: var(--dds-border-neutral-subtle))
--dds-checkbox-readonly-background-colorThe background color when the checkbox is readonly. (default: var(--dds-background-neutral-subtle))
--dds-checkbox-readonly-icon-colorThe color of the checkbox icon when readonly. (default: var(--dds-text-neutral-base))
How to Use CSS Custom Properties

CSS custom properties (CSS variables) can be set directly on the component or in your stylesheet:

Method 1: Inline styles (Quick customization)

<dap-ds-checkbox
  style="--dds-checkbox-size: value; --dds-checkbox-border-width: value;">
  Checkbox
</dap-ds-checkbox>

Method 2: CSS classes (Reusable styles)

.my-custom-dap-ds-checkbox {
  --dds-checkbox-size: value;
  --dds-checkbox-border-width: value;
  --dds-checkbox-border-radius: value;
}
<dap-ds-checkbox class="my-custom-dap-ds-checkbox">
  Checkbox
</dap-ds-checkbox>

Method 3: Global theme customization

/* Apply to all instances */
dap-ds-checkbox {
  --dds-checkbox-size: value;
  --dds-checkbox-border-width: value;
}

CSS custom properties inherit through the Shadow DOM, making them perfect for theming. Changes apply immediately without rebuilding.