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.
React
const Preview = () => { return <Radio label='Radio' value='value' name='name' />; }; render(<Preview />)
Use Radio when
- the user must choose one of several options in a form
Avoid Radio when
- the user should be able to choose more than one option, use
Checkboxinstead
Example
Grouping
Use a legend to ask the question, and include a description if additional explanation is needed.
React
const GroupEn = () => { return ( <Fieldset> <Fieldset.Legend>How would you like us to contact you?</Fieldset.Legend> <Fieldset.Description> Choose the method that works best for you. We use this only to send important updates about your case. </Fieldset.Description> <Radio label='Email' description='We will use the email address you provided earlier (name@example.com)' value='email' name='contact' /> <Radio label='SMS' description='We will use the phone number you provided earlier (99 99 99 99)' value='sms' name='contact' /> <Radio label='Letter' description='Delivery may take 3-5 working days, depending on the postal service.' value='letter' name='contact' /> </Fieldset> ); }; render(<GroupEn />)
With error
If the user attempts to continue without answering a required question, the error message should apply to the entire group of options.
React
const WithErrorEn = () => { return ( <Fieldset> <Fieldset.Legend>Which district do you live in?</Fieldset.Legend> <Fieldset.Description> Trondheim is divided into four districts </Fieldset.Description> <Radio label='Østbyen' value='ostbyen' name='city' aria-invalid='true' /> <Radio label='Lerkendal' value='lerkendal' name='city' aria-invalid='true' /> <Radio label='Heimdal' value='heimdal' name='city' aria-invalid='true' /> <Radio label='Midtbyen' value='midtbyen' name='city' aria-invalid='true' /> <ValidationMessage data-color='danger'> You must choose a district before you can continue. </ValidationMessage> </Fieldset> ); }; render(<WithErrorEn />)
Guidelines
Use Radio when users must select only one option. If they need to select more, use Checkbox.
There should not be more than seven options in one group. If users need more choices, consider using Suggestion or Select. If there is only one choice to make, a Switch or a Checkbox may be more suitable.
Sorting
Sort options alphabetically unless there is a clear reason not to. Be careful about placing the most common option first if the question is personal or value-based, such as sexual orientation or political affiliation.
Placement
Place radio buttons vertically whenever possible. This makes the list easier to scan and the options easier to read. For users who need to zoom in, horizontal layouts can be challenging.
If you have only two options with short labels such as “Yes” and “No”, you may consider placing them side by side. When displayed horizontally, it must be clear which label belongs to which button. Horizontal placement is suitable only when there are two short options, or in rating scales such as “strongly disagree” to “strongly agree” (likert scale (snl.no)).
React
const InlineEn = () => { return ( <Fieldset> <Fieldset.Legend>Contact by email?</Fieldset.Legend> <Fieldset.Description> Confirm whether you would like to be contacted by email. </Fieldset.Description> <div style={{ display: 'flex', flexWrap: 'wrap', gap: 'var(--ds-size-6)' }} > <Radio name='my-inline' label='Yes' value='yes' /> <Radio name='my-inline' label='No' value='no' /> </div> </Fieldset> ); }; render(<InlineEn />)
Avoid pre-selected options
Consider carefully whether you really need a pre-selected option.
It may have the opposite effect of what you intend, users may feel influenced towards a particular choice, or may not realise they need to make an active decision.
Text
A group with several options should always have a heading (<legend>) and, if needed, a description (description) for further explanation. The description should appear immediately after the legend and provide the necessary information before the user makes a choice.
Do
Don't
If one or more radio buttons require a description, it should be placed directly below the corresponding answer option (<label>).
Answer options should be as short as possible, and each option should follow the same linguistic form.
Edit this page on github.com (opens in a new tab)