Skip to main content

Components

Checkbox

Checkbox allows users to select one or more options. It can also be used in situations where the user needs to confirm something.

disabled
Description

Disables element @note Avoid using if possible for accessibility purposes

Type
boolean
readOnly
Description

Toggle `readOnly`

Type
boolean
aria-label
Description

Optional aria-label

Type
string
label
Description

Checkbox label

Type
ReactNode
description
Description

Description for field

Type
ReactNode
value
Description

Value of the `input` element

Type
string | number | readonly string[]
error
Description

Error message for field

Type
ReactNode
aria-labelledby
Type
string
NameTypeDefaultDescription
disabledboolean-

Disables element @note Avoid using if possible for accessibility purposes

readOnlyboolean-

Toggle `readOnly`

aria-labelstring-

Optional aria-label

labelReactNode-

Checkbox label

descriptionReactNode-

Description for field

valuestring | number | readonly string[]-

Value of the `input` element

errorReactNode-

Error message for field

aria-labelledbystring-

-

Usage

Examples

Grouping

Use Fieldset and useCheckboxGroup for grouping multiple options.

Indeterminate checkbox

Add allowIndeterminate: true to getCheckboxProps to create a parent Checkbox that can select or clear all options. This activates an additional state, indeterminate, next to checked and unchecked. It is displayed with a horizontal line when one or more Checkbox are selected in the group. It will be displayed as a regular Checkbox if everyone in the group has the same state.

HTML

Checkbox is a composite component, so in HTML you have to build it from multiple components. We use Fieldset, Label and Input to create a Checkbox.

The code below shows how you can visually build a Checkbox in HTML, but you have to make sure that <input> is connected to <label> and description.

In Fieldset

The code below is an example of how to use Checkbox inside <fieldset>. Note that we only show one `Checkbox' here, in practice this will often be several.

CSS variables and data attributes

Checkbox is a composite component, so we show variables and data attributes from ds-input here.

CSS Variables
NameValue
--dsc-input-padding-blockvar(--ds-size-2)
--dsc-input-padding-inlinevar(--ds-size-3)
--dsc-input-paddingvar(--dsc-input-padding-block) var(--dsc-input-padding-inline)
--dsc-input-size--togglevar(--ds-size-6)
--dsc-input-sizevar(--ds-size-12)
--dsc-input-background--readonlyvar(--ds-color-neutral-surface-tinted)
--dsc-input-backgroundvar(--ds-color-neutral-surface-default)
--dsc-input-border-color--readonlyvar(--ds-color-neutral-border-subtle)
--dsc-input-border-colorvar(--ds-color-neutral-border-default)
--dsc-input-border-stylesolid
--dsc-input-border-width--togglemax(var(--ds-border-width-default),calc(var(--ds-size-1)/2))
--dsc-input-border-widthvar(--ds-border-width-default)
--dsc-input-outline-color--hovervar(--ds-color-neutral-border-default)
--dsc-input-outline-color--toggle--hovervar(--dsc-input-accent-color)
--dsc-input-outline-width--hovervar(--ds-border-width-default)
--dsc-input-outline-style--hoversolid
--dsc-input-color--readonlyvar(--ds-color-neutral-text-default)
--dsc-input-colorvar(--ds-color-neutral-text-default)
--dsc-input-stroke-colorvar(--ds-color-base-contrast-default)
--dsc-input-stroke-color--invalidvar(--ds-color-danger-base-contrast-default)
--dsc-input-stroke-width0.05em
--dsc-input-accent-colorvar(--ds-color-base-default)
--dsc-input-accent-color--invalidvar(--ds-color-danger-text-subtle)
--dsc-input-line-heightvar(--ds-line-height-md)
Data Attributes
NameValue
data-widthauto
Edit this page on github.com (opens in a new tab)