Components Radios
<div class="govuk-form-group">
<fieldset class="govuk-fieldset" aria-describedby="changed-name-hint">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--xl">
<h1 class="govuk-fieldset__heading">
Have you changed your name?
</h1>
</legend>
<span id="changed-name-hint" class="govuk-hint">
This includes changing your last name or spelling your name differently.
</span>
<div class="govuk-radios govuk-radios--inline">
<div class="govuk-radios__item">
<input class="govuk-radios__input" id="changed-name-1" name="changed-name" type="radio" value="yes">
<label class="govuk-label govuk-radios__label" for="changed-name-1">
Yes
</label>
</div>
<div class="govuk-radios__item">
<input class="govuk-radios__input" id="changed-name-2" name="changed-name" type="radio" value="no">
<label class="govuk-label govuk-radios__label" for="changed-name-2">
No
</label>
</div>
</div>
</fieldset>
</div>
{% from 'radios/macro.njk' import govukRadios %}
{{ govukRadios({
classes: "govuk-radios--inline",
idPrefix: "changed-name",
name: "changed-name",
fieldset: {
legend: {
text: 'Have you changed your name?',
isPageHeading: true,
classes: 'govuk-fieldset__legend--xl'
}
},
hint: {
text: "This includes changing your last name or spelling your name differently."
},
items: [
{
value: "yes",
text: "Yes"
},
{
value: "no",
text: "No"
}
]
}) }} You can configure this component using the Nunjucks macro arguments.
When to use this component
Use the radios component when users can only select one option from a list.
When not to use this component
Don’t use the radios component if users might need to select more than one option. In this case, you should use the checkboxes component instead.
How it works
There are 2 ways to use the radios component. You can use HTML or, if you are using Nunjucks or the GOV.UK Prototype Kit, you can use the Nunjucks macro.
Stacked radios
When there are more than 2 options, radios should be stacked, like so:
<div class="govuk-form-group">
<fieldset class="govuk-fieldset">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--xl">
<h1 class="govuk-fieldset__heading">
Where do you live?
</h1>
</legend>
<div class="govuk-radios">
<div class="govuk-radios__item">
<input class="govuk-radios__input" id="where-do-you-live-1" name="where-do-you-live" type="radio" value="england">
<label class="govuk-label govuk-radios__label" for="where-do-you-live-1">
England
</label>
</div>
<div class="govuk-radios__item">
<input class="govuk-radios__input" id="where-do-you-live-2" name="where-do-you-live" type="radio" value="scotland">
<label class="govuk-label govuk-radios__label" for="where-do-you-live-2">
Scotland
</label>
</div>
<div class="govuk-radios__item">
<input class="govuk-radios__input" id="where-do-you-live-3" name="where-do-you-live" type="radio" value="wales">
<label class="govuk-label govuk-radios__label" for="where-do-you-live-3">
Wales
</label>
</div>
<div class="govuk-radios__item">
<input class="govuk-radios__input" id="where-do-you-live-4" name="where-do-you-live" type="radio" value="northern-ireland">
<label class="govuk-label govuk-radios__label" for="where-do-you-live-4">
Northern Ireland
</label>
</div>
</div>
</fieldset>
</div>
{% from 'radios/macro.njk' import govukRadios %}
{{ govukRadios({
idPrefix: "where-do-you-live",
name: "where-do-you-live",
fieldset: {
legend: {
text: 'Where do you live?',
isPageHeading: true,
classes: 'govuk-fieldset__legend--xl'
}
},
items: [
{
value: "england",
text: "England"
},
{
value: "scotland",
text: "Scotland"
},
{
value: "wales",
text: "Wales"
},
{
value: "northern-ireland",
text: "Northern Ireland"
}
]
}) }} You can configure this component using the Nunjucks macro arguments.
Inline radios
If there are only 2 options, you can either stack the radios or display them inline, like so:
<div class="govuk-form-group">
<fieldset class="govuk-fieldset" aria-describedby="changed-name-hint">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--xl">
<h1 class="govuk-fieldset__heading">
Have you changed your name?
</h1>
</legend>
<span id="changed-name-hint" class="govuk-hint">
This includes changing your last name or spelling your name differently.
</span>
<div class="govuk-radios govuk-radios--inline">
<div class="govuk-radios__item">
<input class="govuk-radios__input" id="changed-name-1" name="changed-name" type="radio" value="yes">
<label class="govuk-label govuk-radios__label" for="changed-name-1">
Yes
</label>
</div>
<div class="govuk-radios__item">
<input class="govuk-radios__input" id="changed-name-2" name="changed-name" type="radio" value="no">
<label class="govuk-label govuk-radios__label" for="changed-name-2">
No
</label>
</div>
</div>
</fieldset>
</div>
{% from 'radios/macro.njk' import govukRadios %}
{{ govukRadios({
classes: "govuk-radios--inline",
idPrefix: "changed-name",
name: "changed-name",
fieldset: {
legend: {
text: 'Have you changed your name?',
isPageHeading: true,
classes: 'govuk-fieldset__legend--xl'
}
},
hint: {
text: "This includes changing your last name or spelling your name differently."
},
items: [
{
value: "yes",
text: "Yes"
},
{
value: "no",
text: "No"
}
]
}) }} You can configure this component using the Nunjucks macro arguments.
Conditionally revealing content
You can add conditionally revealing content to radios, so users only see content when it’s relevant to them. For example, you could reveal an email address input only when a user chooses to be contacted by email.
<div class="govuk-form-group">
<fieldset class="govuk-fieldset">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--m">
<h1 class="govuk-fieldset__heading">
How do you want to be contacted?
</h1>
</legend>
<div class="govuk-radios" data-module="radios">
<div class="govuk-radios__item">
<input class="govuk-radios__input" id="how-contacted-conditional-1" name="how-contacted" type="radio" value="email" data-aria-controls="conditional-how-contacted-conditional-1">
<label class="govuk-label govuk-radios__label" for="how-contacted-conditional-1">
Email
</label>
</div>
<div class="govuk-radios__conditional" id="conditional-how-contacted-conditional-1">
<div class="govuk-form-group">
<label class="govuk-label" for="contact-by-email">
Email address
</label>
<input class="govuk-input govuk-!-width-one-third" id="contact-by-email" name="contact-by-email" type="text">
</div>
</div>
<div class="govuk-radios__item">
<input class="govuk-radios__input" id="how-contacted-conditional-2" name="how-contacted" type="radio" value="phone" data-aria-controls="conditional-how-contacted-conditional-2">
<label class="govuk-label govuk-radios__label" for="how-contacted-conditional-2">
Phone
</label>
</div>
<div class="govuk-radios__conditional" id="conditional-how-contacted-conditional-2">
<div class="govuk-form-group">
<label class="govuk-label" for="contact-by-phone">
Phone number
</label>
<input class="govuk-input govuk-!-width-one-third" id="contact-by-phone" name="contact-by-phone" type="text">
</div>
</div>
<div class="govuk-radios__item">
<input class="govuk-radios__input" id="how-contacted-conditional-3" name="how-contacted" type="radio" value="text" data-aria-controls="conditional-how-contacted-conditional-3">
<label class="govuk-label govuk-radios__label" for="how-contacted-conditional-3">
Text message
</label>
</div>
<div class="govuk-radios__conditional" id="conditional-how-contacted-conditional-3">
<div class="govuk-form-group">
<label class="govuk-label" for="contact-by-text">
Mobile phone number
</label>
<input class="govuk-input govuk-!-width-one-third" id="contact-by-text" name="contact-by-text" type="text">
</div>
</div>
</div>
</fieldset>
</div>
{% from 'radios/macro.njk' import govukRadios %}
{% from "input/macro.njk" import govukInput %}
{% set emailHtml %}
{{ govukInput({
id: "contact-by-email",
name: "contact-by-email",
classes: "govuk-!-width-one-third",
label: {
text: "Email address"
}
}) }}
{% endset -%}
{% set phoneHtml %}
{{ govukInput({
id: "contact-by-phone",
name: "contact-by-phone",
classes: "govuk-!-width-one-third",
label: {
text: "Phone number"
}
}) }}
{% endset -%}
{% set textHtml %}
{{ govukInput({
id: "contact-by-text",
name: "contact-by-text",
classes: "govuk-!-width-one-third",
label: {
text: "Mobile phone number"
}
}) }}
{% endset -%}
{{ govukRadios({
idPrefix: "how-contacted-conditional",
name: "how-contacted",
fieldset: {
legend: {
text: "How do you want to be contacted?",
isPageHeading: true,
classes: "govuk-fieldset__legend--m"
}
},
items: [
{
value: "email",
text: "Email",
conditional: {
html: emailHtml
}
},
{
value: "phone",
text: "Phone",
conditional: {
html: phoneHtml
}
},
{
value: "text",
text: "Text message",
conditional: {
html: textHtml
}
}
]
}) }} You can configure this component using the Nunjucks macro arguments.
Keep it simple - if you need to add a lot of content, consider showing it on the next page in the process instead.
Research on this component
Read a blog post about updates to the radios and checkboxes components.
Get in touch
If you’ve got a question, idea or suggestion share it in #govuk-design-system on cross-government Slack (open in app) or email the Design System team