A set of interactive radio buttons where only one can be selected at a time.
<RadioGroup.Root defaultValue="1">
<Flex gap="2" direction="column">
<Text as="label" size="2">
<Flex gap="2">
<RadioGroup.Item value="1" /> Default
</Flex>
</Text>
<Text as="label" size="2">
<Flex gap="2">
<RadioGroup.Item value="2" /> Comfortable
</Flex>
</Text>
<Text as="label" size="2">
<Flex gap="2">
<RadioGroup.Item value="3" /> Compact
</Flex>
</Text>
</Flex>
</RadioGroup.Root>
This component inherits props from the Radio Group primitive and supports common margin props.
Contains all the parts of a radio group.
An item in the group that can be checked.
Use the size
prop to control the radiobutton size.
<Flex align="center" gap="2">
<RadioGroup.Root size="1" defaultValue="1">
<RadioGroup.Item value="1" />
</RadioGroup.Root>
<RadioGroup.Root size="2" defaultValue="1">
<RadioGroup.Item value="1" />
</RadioGroup.Root>
<RadioGroup.Root size="3" defaultValue="1">
<RadioGroup.Item value="1" />
</RadioGroup.Root>
</Flex>
Use the variant
prop to control the visual style of the radio buttons.
<Flex gap="2">
<Flex direction="column" asChild gap="2">
<RadioGroup.Root variant="surface" defaultValue="1">
<RadioGroup.Item value="1" />
<RadioGroup.Item value="2" />
</RadioGroup.Root>
</Flex>
<Flex direction="column" asChild gap="2">
<RadioGroup.Root variant="classic" defaultValue="1">
<RadioGroup.Item value="1" />
<RadioGroup.Item value="2" />
</RadioGroup.Root>
</Flex>
<Flex direction="column" asChild gap="2">
<RadioGroup.Root variant="soft" defaultValue="1">
<RadioGroup.Item value="1" />
<RadioGroup.Item value="2" />
</RadioGroup.Root>
</Flex>
</Flex>
Use the color
prop to assign a specific color, ignoring the global theme.
<Flex gap="2">
<RadioGroup.Root color="indigo" defaultValue="1">
<RadioGroup.Item value="1" />
</RadioGroup.Root>
<RadioGroup.Root color="cyan" defaultValue="1">
<RadioGroup.Item value="1" />
</RadioGroup.Root>
<RadioGroup.Root color="orange" defaultValue="1">
<RadioGroup.Item value="1" />
</RadioGroup.Root>
<RadioGroup.Root color="crimson" defaultValue="1">
<RadioGroup.Item value="1" />
</RadioGroup.Root>
</Flex>
Use the highContrast
prop to increase color contrast with the background.
<Grid rows="2" gap="2" display="inline-grid" flow="column">
<RadioGroup.Root color="indigo" defaultValue="1">
<RadioGroup.Item value="1" />
</RadioGroup.Root>
<RadioGroup.Root color="indigo" defaultValue="1" highContrast>
<RadioGroup.Item value="1" />
</RadioGroup.Root>
<RadioGroup.Root color="cyan" defaultValue="1">
<RadioGroup.Item value="1" />
</RadioGroup.Root>
<RadioGroup.Root color="cyan" defaultValue="1" highContrast>
<RadioGroup.Item value="1" />
</RadioGroup.Root>
<RadioGroup.Root color="orange" defaultValue="1">
<RadioGroup.Item value="1" />
</RadioGroup.Root>
<RadioGroup.Root color="orange" defaultValue="1" highContrast>
<RadioGroup.Item value="1" />
</RadioGroup.Root>
<RadioGroup.Root color="crimson" defaultValue="1">
<RadioGroup.Item value="1" />
</RadioGroup.Root>
<RadioGroup.Root color="crimson" defaultValue="1" highContrast>
<RadioGroup.Item value="1" />
</RadioGroup.Root>
</Grid>
Composing RadioGroup.Item
within Text
automatically centers it with the first line of text.
<Flex direction="column" gap="3">
<RadioGroup.Root size="1" defaultValue="1">
<Text as="label" size="2">
<Flex gap="2">
<RadioGroup.Item value="1" /> Default
</Flex>
</Text>
<Text as="label" size="2">
<Flex gap="2">
<RadioGroup.Item value="2" /> Compact
</Flex>
</Text>
</RadioGroup.Root>
<RadioGroup.Root size="2" defaultValue="1">
<Text as="label" size="3">
<Flex gap="2">
<RadioGroup.Item value="1" /> Default
</Flex>
</Text>
<Text as="label" size="3">
<Flex gap="2">
<RadioGroup.Item value="2" /> Compact
</Flex>
</Text>
</RadioGroup.Root>
<RadioGroup.Root size="3" defaultValue="1">
<Text as="label" size="4">
<Flex gap="2">
<RadioGroup.Item value="1" /> Default
</Flex>
</Text>
<Text as="label" size="4">
<Flex gap="2">
<RadioGroup.Item value="2" /> Compact
</Flex>
</Text>
</RadioGroup.Root>
</Flex>
It is automatically well-aligned with multi-line text too.
Use the native disabled
attribute to create a disabled radiobutton.
<Flex direction="column" gap="2">
<RadioGroup.Root defaultValue="2">
<Flex direction="column" gap="2">
<Text as="label" size="2">
<Flex gap="2">
<RadioGroup.Item value="1" />
Off
</Flex>
</Text>
<Text as="label" size="2">
<Flex gap="2">
<RadioGroup.Item value="2" />
On
</Flex>
</Text>
</Flex>
</RadioGroup.Root>
<RadioGroup.Root defaultValue="2">
<Flex direction="column" gap="2">
<Text as="label" size="2" color="gray">
<Flex gap="2">
<RadioGroup.Item value="1" disabled />
Off
</Flex>
</Text>
<Text as="label" size="2" color="gray">
<Flex gap="2">
<RadioGroup.Item value="2" disabled />
On
</Flex>
</Text>
</Flex>
</RadioGroup.Root>
</Flex>