Selects a single value, typically for submission in a form.
<Text as="label" size="2">
<Flex gap="2">
<Checkbox defaultChecked /> Agree to Terms and Conditions
</Flex>
</Text>
This component inherits props from the Checkbox primitive and supports common margin props.
Use the size
prop to control the size of the checkbox.
<Flex align="center" gap="2">
<Checkbox size="1" defaultChecked />
<Checkbox size="2" defaultChecked />
<Checkbox size="3" defaultChecked />
</Flex>
Use the variant
prop to control the visual style of the checkbox.
<Grid rows="2" gap="2" display="inline-grid" flow="column">
<Checkbox variant="surface" defaultChecked />
<Checkbox variant="surface" />
<Checkbox variant="classic" defaultChecked />
<Checkbox variant="classic" />
<Checkbox variant="soft" defaultChecked />
<Checkbox variant="soft" />
</Grid>
Use the color
prop to assign a specific color, ignoring the global theme.
<Flex gap="2">
<Checkbox color="indigo" defaultChecked />
<Checkbox color="cyan" defaultChecked />
<Checkbox color="orange" defaultChecked />
<Checkbox color="crimson" defaultChecked />
</Flex>
Use the highContrast
prop to increase color contrast with the background.
<Grid rows="2" gap="2" display="inline-grid" flow="column">
<Checkbox color="indigo" defaultChecked />
<Checkbox color="indigo" defaultChecked highContrast />
<Checkbox color="cyan" defaultChecked />
<Checkbox color="cyan" defaultChecked highContrast />
<Checkbox color="orange" defaultChecked />
<Checkbox color="orange" defaultChecked highContrast />
<Checkbox color="crimson" defaultChecked />
<Checkbox color="crimson" defaultChecked highContrast />
</Grid>
Composing Checkbox
within Text
automatically centers it with the first line of text.
<Flex direction="column" gap="3">
<Text as="label" size="2">
<Flex gap="2">
<Checkbox size="1" defaultChecked /> Agree to Terms and Conditions
</Flex>
</Text>
<Text as="label" size="3">
<Flex gap="2">
<Checkbox size="2" defaultChecked /> Agree to Terms and Conditions
</Flex>
</Text>
<Text as="label" size="4">
<Flex gap="2">
<Checkbox size="3" defaultChecked /> Agree to Terms and Conditions
</Flex>
</Text>
</Flex>
It is automatically well-aligned with multi-line text too.
<Box style={{ maxWidth: 300 }}>
<Text as="label" size="3">
<Flex gap="2">
<Checkbox defaultChecked /> I understand that these documents are
confidential and cannot be shared with a third party.
</Flex>
</Text>
</Box>
Use the native disabled
attribute to create a disabled checkbox.
<Flex direction="column" gap="2">
<Text as="label" size="2">
<Flex gap="2">
<Checkbox />
Not checked
</Flex>
</Text>
<Text as="label" size="2">
<Flex gap="2">
<Checkbox defaultChecked />
Checked
</Flex>
</Text>
<Text as="label" size="2" color="gray">
<Flex gap="2">
<Checkbox disabled />
Not checked
</Flex>
</Text>
<Text as="label" size="2" color="gray">
<Flex gap="2">
<Checkbox disabled defaultChecked />
Checked
</Flex>
</Text>
</Flex>