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.
<ds-field class="ds-field">
<input
class="ds-input"
type="radio"
name="name"
value="value"
/>
<label class="ds-label" data-weight="regular">Radio</label>
</ds-field>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 checkbox instead
Example
Grouping
Use a legend to ask the question, and include a description if additional explanation is needed.
<fieldset class="ds-fieldset">
<legend class="ds-label">How would you like us to contact you?</legend>
<p class="ds-paragraph">
Choose the method that works best for you. We use this only to send
important updates about your case.
</p>
<ds-field class="ds-field">
<input
class="ds-input"
type="radio"
name="contact"
value="email"
/>
<label class="ds-label" data-weight="regular">Email</label>
<div data-field="description">We will use the email address you provided earlier (name@example.com)</div>
</ds-field>
<ds-field class="ds-field">
<input
class="ds-input"
type="radio"
name="contact"
value="sms"
/>
<label class="ds-label" data-weight="regular">SMS</label>
<div data-field="description">We will use the phone number you provided earlier (99 99 99 99)</div>
</ds-field>
<ds-field class="ds-field">
<input
class="ds-input"
type="radio"
name="contact"
value="letter"
/>
<label class="ds-label" data-weight="regular">Letter</label>
<div data-field="description">Delivery may take 3-5 working days, depending on the postal service.</div>
</ds-field>
</fieldset>const GroupEn = () => { const { getRadioProps } = useRadioGroup({ name: 'contact', value: 'email', }); 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)' {...getRadioProps('email')} /> <Radio label='SMS' description='We will use the phone number you provided earlier (99 99 99 99)' {...getRadioProps('sms')} /> <Radio label='Letter' description='Delivery may take 3-5 working days, depending on the postal service.' {...getRadioProps('letter')} /> </Fieldset> ); }; render(<GroupEn />)
Outline
There is a variant of radio called outline. It adds extra padding and a border around the selection, increasing the clickable area.
<fieldset class="ds-fieldset">
<legend class="ds-label">Which course level fits you best?</legend>
<p class="ds-paragraph">Choose the level that best describes your experience with the topic.</p>
<ds-field class="ds-field" data-variant="outline">
<input
class="ds-input"
type="radio"
name="course-level"
value="beginner"
/>
<label class="ds-label" data-weight="regular">Beginner</label>
<div data-field="description">
Best for you if you are completely new and want a gentle introduction.
</div>
</ds-field>
<ds-field class="ds-field" data-variant="outline">
<input
class="ds-input"
type="radio"
name="course-level"
value="intermediate"
/>
<label class="ds-label" data-weight="regular">Intermediate</label>
<div data-field="description">Best for you if you know the basics and want to go deeper.</div>
</ds-field>
<ds-field class="ds-field" data-variant="outline">
<input
class="ds-input"
type="radio"
name="course-level"
value="expert"
/>
<label class="ds-label" data-weight="regular">Expert</label>
<div data-field="description">Best for you if you want advanced topics and hands-on cases.</div>
</ds-field>
</fieldset>const OutlineEn = () => { const { getRadioProps } = useRadioGroup({ name: 'course-level', variant: 'outline', }); return ( <Fieldset> <Fieldset.Legend>Which course level fits you best?</Fieldset.Legend> <Fieldset.Description> Choose the level that best describes your experience with the topic. </Fieldset.Description> <Radio label='Beginner' description='Best for you if you are completely new and want a gentle introduction.' {...getRadioProps('beginner')} /> <Radio label='Intermediate' description='Best for you if you know the basics and want to go deeper.' {...getRadioProps('intermediate')} /> <Radio label='Expert' description='Best for you if you want advanced topics and hands-on cases.' {...getRadioProps('expert')} /> </Fieldset> ); }; render(<OutlineEn />)
With error
If the user attempts to continue without answering a required question, the error message should apply to the entire group of options.
<fieldset class="ds-fieldset">
<legend class="ds-label">Which district do you live in?</legend>
<p class="ds-paragraph">Trondheim is divided into four districts</p>
<ds-field class="ds-field">
<input
class="ds-input"
type="radio"
name="city"
value="ostbyen"
/>
<label class="ds-label" data-weight="regular">Østbyen</label>
</ds-field>
<ds-field class="ds-field">
<input
class="ds-input"
type="radio"
name="city"
value="lerkendal"
/>
<label class="ds-label" data-weight="regular">Lerkendal</label>
</ds-field>
<ds-field class="ds-field">
<input
class="ds-input"
type="radio"
name="city"
value="heimdal"
/>
<label class="ds-label" data-weight="regular">Heimdal</label>
</ds-field>
<ds-field class="ds-field">
<input
class="ds-input"
type="radio"
name="city"
value="midtbyen"
/>
<label class="ds-label" data-weight="regular">Midtbyen</label>
</ds-field>
<p
class="ds-validation-message"
data-field="validation"
data-color="danger"
>You must choose a district before you can continue.</p>
</fieldset>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' /> <Radio label='Lerkendal' value='lerkendal' name='city' /> <Radio label='Heimdal' value='heimdal' name='city' /> <Radio label='Midtbyen' value='midtbyen' name='city' /> <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.
When using a horizontal layout, it must be clear which text belongs to which button. You can use a horizontal layout when there are only two options with short labels, such as “Yes” and “No”, or in a rating scale ranging from “strongly disagree” to “strongly agree”. Likert scale (snl.no).
<fieldset class="ds-fieldset">
<legend class="ds-label">Contact by email?</legend>
<p class="ds-paragraph">Confirm whether you would like to be contacted by email.</p>
<div style="display:flex;flex-wrap:wrap;gap:var(--ds-size-6)">
<ds-field class="ds-field">
<input
class="ds-input"
type="radio"
name="my-inline"
value="yes"
/>
<label class="ds-label" data-weight="regular">Yes</label>
</ds-field>
<ds-field class="ds-field">
<input
class="ds-input"
type="radio"
name="my-inline"
value="no"
/>
<label class="ds-label" data-weight="regular">No</label>
</ds-field>
</div>
</fieldset>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 />)
Be cautious with preselected options
Consider whether a preselected option is appropriate for the context. A preselected option can influence the user's ability to make an informed choice, and some users may experience it as manipulative or discriminatory.
Text
A group with multiple options should always have a legend and option labels. Both can include a description to provide additional explanation. When the description is intended to help users understand the question and provide necessary information before they make a choice, it should be placed directly after the legend.
Read more about how to write labels, questions and answer options in forms.
Do
const DoIconEn = () => {
return (
<Fieldset>
<Fieldset.Legend>Would you like a meeting?</Fieldset.Legend>
<Fieldset.Description>
You can request a meeting with us where we explain the contents of the
decision.
</Fieldset.Description>
<Radio label='Yes' value='yes' name='meeting' />
<Radio label='No' value='no' name='meeting' />
</Fieldset>
);
};
render(<DoIconEn />)<fieldset class="ds-fieldset"><legend class="ds-label">Would you like a meeting?</legend><p class="ds-paragraph">You can request a meeting with us where we explain the contents of the decision.</p><ds-field class="ds-field"><input class="ds-input" type="radio" name="meeting" value="yes"/><label class="ds-label" data-weight="regular">Yes</label></ds-field><ds-field class="ds-field"><input class="ds-input" type="radio" name="meeting" value="no"/><label class="ds-label" data-weight="regular">No</label></ds-field></fieldset>Don't
const DontIconEn = () => {
return (
<Fieldset>
<Fieldset.Legend>Would you like a meeting?</Fieldset.Legend>
<Radio label='Yes' value='yes' name='meeting-dont' />
<Radio label='No' value='no' name='meeting-dont' />
<Paragraph>
You can request a meeting with us where we explain the contents of the
decision.
</Paragraph>
</Fieldset>
);
};
render(<DontIconEn />)<fieldset class="ds-fieldset"><legend class="ds-label">Would you like a meeting?</legend><ds-field class="ds-field"><input class="ds-input" type="radio" name="meeting-dont" value="yes"/><label class="ds-label" data-weight="regular">Yes</label></ds-field><ds-field class="ds-field"><input class="ds-input" type="radio" name="meeting-dont" value="no"/><label class="ds-label" data-weight="regular">No</label></ds-field><p class="ds-paragraph">You can request a meeting with us where we explain the contents of the decision.</p></fieldset>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)