Skip to main content

Components

Radio

A Radio is an option the user can select. Use multiple Radio to show a list of options. Users can switch between the options, but can only select one.

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

Radio 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-

Radio 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 around a group of radio buttons to provide a common prompt (<legend>) and optionally a description (description).

With Error

Here we must use Fieldset, because it activates the correct style and ensures that the content has the correct connections for accessibility.

Readonly

Fields with the readonly attribute are included in the tab order. Users can copy the content but not edit it. Information is included when the form is submitted.

Readonly fields can be confusing for some users. Not everyone will understand why they cannot change the content of the field. We therefore recommend avoiding readonly as much as possible.

Inline

Radio can be positioned horizontally with flex, but should generally be placed vertically.

HTML

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

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

In Fieldset

The code below is an example of how to use multiple Radio inside <fieldset>.

CSS variables and data attributes

Checkbox is a composite component, and therefore 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)