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>
Nunjucks macro options

Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.

Some options are required for the macro to work; these are marked as "Required" in the option description.

If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against cross-site scripting exploits.

Primary options
Name Type Description
fieldset object Options for the fieldset component (e.g. legend). See fieldset.
hint object Options for the hint component (e.g. text). See hint.
errorMessage object Options for the errorMessage component (e.g. text). See errorMessage.
formGroup object Options for the form-group wrapper See formGroup.
idPrefix string String to prefix id for each checkbox item if no id is specified on each item. If idPrefix is not passed, fallback to using the name attribute instead.
name string Required. Name attribute for each radio item.
items array Required. Array of radio items objects. See items.
classes string Classes to add to the radio container.
attributes object HTML attributes (for example data attributes) to add to the radio input tag.
Options for formGroup
Name Type Description
classes string Optional classes to add to the form group (e.g. to show error state for the whole group)
Options for items
Name Type Description
text string Required. If html is set, this is not required. Text to use within each radio item label. If html is provided, the text argument will be ignored.
html string Required. If text is set, this is not required. HTML to use within each radio item label. If html is provided, the text argument will be ignored.
id string Specific id attribute for the radio item. If omitted, then idPrefix string will be applied.
name string Required. Specific name for the radio item. If omitted, then component global name string will be applied.
value string Required. Value for the radio input.
label object Provide attributes and classes to each radio item label. See label.
hint object Provide hint to each checkbox item. See hint.
divider string Divider text to separate radio items, for example the text "or".
checked boolean If true, radio will be checked.
conditional string If true, content provided will be revealed when the item is checked.
conditional.html html Provide content for the conditional reveal.
disabled boolean If true, radio will be disabled.
attributes object HTML attributes (for example data attributes) to add to the radio input tag.
Options for hint
Name Type Description
text string Required. If `html` is set, this is not required. Text to use within the hint. If `html` is provided, the `text` argument will be ignored.
html string Required. If `text` is set, this is not required. HTML to use within the hint. If `html` is provided, the `text` argument will be ignored.
id string Required. Optional id attribute to add to the hint span tag.
classes string Classes to add to the hint span tag.
attributes object HTML attributes (for example data attributes) to add to the hint span tag.
Options for label
Name Type Description
text string Required. If `html` is set, this is not required. Text to use within the label. If `html` is provided, the `text` argument will be ignored.
html string Required. If `text` is set, this is not required. HTML to use within the label. If `html` is provided, the `text` argument will be ignored.
for string Required. The value of the for attribute, the id of the input the label is associated with.
isPageHeading boolean Whether the label also acts as the heading for the page.
classes string Classes to add to the label tag.
attributes object HTML attributes (for example data attributes) to add to the label tag.
{% 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"
    }
  ]
}) }}

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

Do not 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

Radios are grouped together in a <fieldset> with a <legend> that describes them, as shown in the examples on this page. This is usually a question, like ‘Where do you live?’.

If you are asking just one question per page as recommended, you can set the contents of the <legend> as the page heading. This is good practice as it means that users of screen readers will only hear the contents once.

Read more about why and how to set legends as headings.

Unlike with checkboxes, users can only select one option from a list of radios. Do not assume that users will know how many options they can select based on the visual difference between radios and checkboxes alone.

If needed, add a hint explaining this, for example, ‘Select one option’.

Do not pre-select radio options as this makes it more likely that users will:

  • not realise they’ve missed a question
  • submit the wrong answer

Users cannot go back to having no option selected once they have selected one, without refreshing their browser window. Therefore, you should include ‘None of the above’ or ‘I do not know’ if they are valid options.

Order radio options alphabetically by default.

In some cases, it can be helpful to order them from most-to-least common options, for example, you could order options for ‘Where do you live?’ based on population size.

However you should do this with extreme caution as it can reinforce bias in your service. If in doubt, order alphabetically.

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>
Nunjucks macro options

Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.

Some options are required for the macro to work; these are marked as "Required" in the option description.

If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against cross-site scripting exploits.

Primary options
Name Type Description
fieldset object Options for the fieldset component (e.g. legend). See fieldset.
hint object Options for the hint component (e.g. text). See hint.
errorMessage object Options for the errorMessage component (e.g. text). See errorMessage.
formGroup object Options for the form-group wrapper See formGroup.
idPrefix string String to prefix id for each checkbox item if no id is specified on each item. If idPrefix is not passed, fallback to using the name attribute instead.
name string Required. Name attribute for each radio item.
items array Required. Array of radio items objects. See items.
classes string Classes to add to the radio container.
attributes object HTML attributes (for example data attributes) to add to the radio input tag.
Options for formGroup
Name Type Description
classes string Optional classes to add to the form group (e.g. to show error state for the whole group)
Options for items
Name Type Description
text string Required. If html is set, this is not required. Text to use within each radio item label. If html is provided, the text argument will be ignored.
html string Required. If text is set, this is not required. HTML to use within each radio item label. If html is provided, the text argument will be ignored.
id string Specific id attribute for the radio item. If omitted, then idPrefix string will be applied.
name string Required. Specific name for the radio item. If omitted, then component global name string will be applied.
value string Required. Value for the radio input.
label object Provide attributes and classes to each radio item label. See label.
hint object Provide hint to each checkbox item. See hint.
divider string Divider text to separate radio items, for example the text "or".
checked boolean If true, radio will be checked.
conditional string If true, content provided will be revealed when the item is checked.
conditional.html html Provide content for the conditional reveal.
disabled boolean If true, radio will be disabled.
attributes object HTML attributes (for example data attributes) to add to the radio input tag.
Options for hint
Name Type Description
text string Required. If `html` is set, this is not required. Text to use within the hint. If `html` is provided, the `text` argument will be ignored.
html string Required. If `text` is set, this is not required. HTML to use within the hint. If `html` is provided, the `text` argument will be ignored.
id string Required. Optional id attribute to add to the hint span tag.
classes string Classes to add to the hint span tag.
attributes object HTML attributes (for example data attributes) to add to the hint span tag.
Options for label
Name Type Description
text string Required. If `html` is set, this is not required. Text to use within the label. If `html` is provided, the `text` argument will be ignored.
html string Required. If `text` is set, this is not required. HTML to use within the label. If `html` is provided, the `text` argument will be ignored.
for string Required. The value of the for attribute, the id of the input the label is associated with.
isPageHeading boolean Whether the label also acts as the heading for the page.
classes string Classes to add to the label tag.
attributes object HTML attributes (for example data attributes) to add to the label tag.
{% 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"
    }
  ]
}) }}

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>
Nunjucks macro options

Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.

Some options are required for the macro to work; these are marked as "Required" in the option description.

If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against cross-site scripting exploits.

Primary options
Name Type Description
fieldset object Options for the fieldset component (e.g. legend). See fieldset.
hint object Options for the hint component (e.g. text). See hint.
errorMessage object Options for the errorMessage component (e.g. text). See errorMessage.
formGroup object Options for the form-group wrapper See formGroup.
idPrefix string String to prefix id for each checkbox item if no id is specified on each item. If idPrefix is not passed, fallback to using the name attribute instead.
name string Required. Name attribute for each radio item.
items array Required. Array of radio items objects. See items.
classes string Classes to add to the radio container.
attributes object HTML attributes (for example data attributes) to add to the radio input tag.
Options for formGroup
Name Type Description
classes string Optional classes to add to the form group (e.g. to show error state for the whole group)
Options for items
Name Type Description
text string Required. If html is set, this is not required. Text to use within each radio item label. If html is provided, the text argument will be ignored.
html string Required. If text is set, this is not required. HTML to use within each radio item label. If html is provided, the text argument will be ignored.
id string Specific id attribute for the radio item. If omitted, then idPrefix string will be applied.
name string Required. Specific name for the radio item. If omitted, then component global name string will be applied.
value string Required. Value for the radio input.
label object Provide attributes and classes to each radio item label. See label.
hint object Provide hint to each checkbox item. See hint.
divider string Divider text to separate radio items, for example the text "or".
checked boolean If true, radio will be checked.
conditional string If true, content provided will be revealed when the item is checked.
conditional.html html Provide content for the conditional reveal.
disabled boolean If true, radio will be disabled.
attributes object HTML attributes (for example data attributes) to add to the radio input tag.
Options for hint
Name Type Description
text string Required. If `html` is set, this is not required. Text to use within the hint. If `html` is provided, the `text` argument will be ignored.
html string Required. If `text` is set, this is not required. HTML to use within the hint. If `html` is provided, the `text` argument will be ignored.
id string Required. Optional id attribute to add to the hint span tag.
classes string Classes to add to the hint span tag.
attributes object HTML attributes (for example data attributes) to add to the hint span tag.
Options for label
Name Type Description
text string Required. If `html` is set, this is not required. Text to use within the label. If `html` is provided, the `text` argument will be ignored.
html string Required. If `text` is set, this is not required. HTML to use within the label. If `html` is provided, the `text` argument will be ignored.
for string Required. The value of the for attribute, the id of the input the label is associated with.
isPageHeading boolean Whether the label also acts as the heading for the page.
classes string Classes to add to the label tag.
attributes object HTML attributes (for example data attributes) to add to the label tag.
{% 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"
    }
  ]
}) }}

Radio items with hints

You can add hints to radio items to provide additional information about the options.

<div class="govuk-form-group">
  <fieldset class="govuk-fieldset" aria-describedby="sign-in-hint">
    <legend class="govuk-fieldset__legend govuk-fieldset__legend--xl">
      <h1 class="govuk-fieldset__heading">
        How do you want to sign in?
      </h1>
    </legend>
    <span id="sign-in-hint" class="govuk-hint">
      You&#39;ll need an account to prove your identity and complete your Self Assessment.
    </span>
    <div class="govuk-radios">
      <div class="govuk-radios__item">
        <input class="govuk-radios__input" id="sign-in-1" name="sign-in" type="radio" value="government-gateway" aria-describedby="sign-in-1-item-hint">
        <label class="govuk-label govuk-radios__label govuk-label--s" for="sign-in-1">
          Sign in with Government Gateway
        </label>
        <span id="sign-in-1-item-hint" class="govuk-hint govuk-radios__hint">
          You&#39;ll have a user ID if you&#39;ve registered for Self Assessment or filed a tax return online before.
        </span>
      </div>
      <div class="govuk-radios__item">
        <input class="govuk-radios__input" id="sign-in-2" name="sign-in" type="radio" value="govuk-verify" aria-describedby="sign-in-2-item-hint">
        <label class="govuk-label govuk-radios__label govuk-label--s" for="sign-in-2">
          Sign in with GOV.UK Verify
        </label>
        <span id="sign-in-2-item-hint" class="govuk-hint govuk-radios__hint">
          You&#39;ll have an account if you&#39;ve already proved your identity with either Barclays, CitizenSafe, Digidentity, Experian, Post Office, Royal Mail or SecureIdentity.
        </span>
      </div>
    </div>
  </fieldset>
</div>
Nunjucks macro options

Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.

Some options are required for the macro to work; these are marked as "Required" in the option description.

If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against cross-site scripting exploits.

Primary options
Name Type Description
fieldset object Options for the fieldset component (e.g. legend). See fieldset.
hint object Options for the hint component (e.g. text). See hint.
errorMessage object Options for the errorMessage component (e.g. text). See errorMessage.
formGroup object Options for the form-group wrapper See formGroup.
idPrefix string String to prefix id for each checkbox item if no id is specified on each item. If idPrefix is not passed, fallback to using the name attribute instead.
name string Required. Name attribute for each radio item.
items array Required. Array of radio items objects. See items.
classes string Classes to add to the radio container.
attributes object HTML attributes (for example data attributes) to add to the radio input tag.
Options for formGroup
Name Type Description
classes string Optional classes to add to the form group (e.g. to show error state for the whole group)
Options for items
Name Type Description
text string Required. If html is set, this is not required. Text to use within each radio item label. If html is provided, the text argument will be ignored.
html string Required. If text is set, this is not required. HTML to use within each radio item label. If html is provided, the text argument will be ignored.
id string Specific id attribute for the radio item. If omitted, then idPrefix string will be applied.
name string Required. Specific name for the radio item. If omitted, then component global name string will be applied.
value string Required. Value for the radio input.
label object Provide attributes and classes to each radio item label. See label.
hint object Provide hint to each checkbox item. See hint.
divider string Divider text to separate radio items, for example the text "or".
checked boolean If true, radio will be checked.
conditional string If true, content provided will be revealed when the item is checked.
conditional.html html Provide content for the conditional reveal.
disabled boolean If true, radio will be disabled.
attributes object HTML attributes (for example data attributes) to add to the radio input tag.
Options for hint
Name Type Description
text string Required. If `html` is set, this is not required. Text to use within the hint. If `html` is provided, the `text` argument will be ignored.
html string Required. If `text` is set, this is not required. HTML to use within the hint. If `html` is provided, the `text` argument will be ignored.
id string Required. Optional id attribute to add to the hint span tag.
classes string Classes to add to the hint span tag.
attributes object HTML attributes (for example data attributes) to add to the hint span tag.
Options for label
Name Type Description
text string Required. If `html` is set, this is not required. Text to use within the label. If `html` is provided, the `text` argument will be ignored.
html string Required. If `text` is set, this is not required. HTML to use within the label. If `html` is provided, the `text` argument will be ignored.
for string Required. The value of the for attribute, the id of the input the label is associated with.
isPageHeading boolean Whether the label also acts as the heading for the page.
classes string Classes to add to the label tag.
attributes object HTML attributes (for example data attributes) to add to the label tag.
{% from "radios/macro.njk" import govukRadios %}

{{ govukRadios({
  idPrefix: "sign-in",
  name: "sign-in",
  fieldset: {
    legend: {
      text: "How do you want to sign in?",
      isPageHeading: true,
      classes: "govuk-fieldset__legend--xl"
    }
  },
  hint: {
    text: "You'll need an account to prove your identity and complete your Self Assessment."
  },
  items: [
    {
      value: "government-gateway",
      text: "Sign in with Government Gateway",
      label: {
        classes: "govuk-label--s"
      },
      hint: {
        text: "You'll have a user ID if you've registered for Self Assessment or filed a tax return online before."
      }
    },
    {
      value: "govuk-verify",
      text: "Sign in with GOV.UK Verify",
      label: {
        classes: "govuk-label--s"
      },
      hint: {
        text: "You'll have an account if you've already proved your identity with either Barclays, CitizenSafe, Digidentity, Experian, Post Office, Royal Mail or SecureIdentity."
      }
    }
  ]
}) }}

Radio items with a text divider

If one or more of your radio options is different from the others, it can help users if you separate them using a text divider. The text is usually the word ‘or’.

<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 class="govuk-radios__divider">or</div>
      <div class="govuk-radios__item">
        <input class="govuk-radios__input" id="where-do-you-live-6" name="where-do-you-live" type="radio" value="abroad">
        <label class="govuk-label govuk-radios__label" for="where-do-you-live-6">
          I am a British citizen living abroad
        </label>
      </div>
    </div>
  </fieldset>
</div>
Nunjucks macro options

Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.

Some options are required for the macro to work; these are marked as "Required" in the option description.

If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against cross-site scripting exploits.

Primary options
Name Type Description
fieldset object Options for the fieldset component (e.g. legend). See fieldset.
hint object Options for the hint component (e.g. text). See hint.
errorMessage object Options for the errorMessage component (e.g. text). See errorMessage.
formGroup object Options for the form-group wrapper See formGroup.
idPrefix string String to prefix id for each checkbox item if no id is specified on each item. If idPrefix is not passed, fallback to using the name attribute instead.
name string Required. Name attribute for each radio item.
items array Required. Array of radio items objects. See items.
classes string Classes to add to the radio container.
attributes object HTML attributes (for example data attributes) to add to the radio input tag.
Options for formGroup
Name Type Description
classes string Optional classes to add to the form group (e.g. to show error state for the whole group)
Options for items
Name Type Description
text string Required. If html is set, this is not required. Text to use within each radio item label. If html is provided, the text argument will be ignored.
html string Required. If text is set, this is not required. HTML to use within each radio item label. If html is provided, the text argument will be ignored.
id string Specific id attribute for the radio item. If omitted, then idPrefix string will be applied.
name string Required. Specific name for the radio item. If omitted, then component global name string will be applied.
value string Required. Value for the radio input.
label object Provide attributes and classes to each radio item label. See label.
hint object Provide hint to each checkbox item. See hint.
divider string Divider text to separate radio items, for example the text "or".
checked boolean If true, radio will be checked.
conditional string If true, content provided will be revealed when the item is checked.
conditional.html html Provide content for the conditional reveal.
disabled boolean If true, radio will be disabled.
attributes object HTML attributes (for example data attributes) to add to the radio input tag.
Options for hint
Name Type Description
text string Required. If `html` is set, this is not required. Text to use within the hint. If `html` is provided, the `text` argument will be ignored.
html string Required. If `text` is set, this is not required. HTML to use within the hint. If `html` is provided, the `text` argument will be ignored.
id string Required. Optional id attribute to add to the hint span tag.
classes string Classes to add to the hint span tag.
attributes object HTML attributes (for example data attributes) to add to the hint span tag.
Options for label
Name Type Description
text string Required. If `html` is set, this is not required. Text to use within the label. If `html` is provided, the `text` argument will be ignored.
html string Required. If `text` is set, this is not required. HTML to use within the label. If `html` is provided, the `text` argument will be ignored.
for string Required. The value of the for attribute, the id of the input the label is associated with.
isPageHeading boolean Whether the label also acts as the heading for the page.
classes string Classes to add to the label tag.
attributes object HTML attributes (for example data attributes) to add to the label tag.
{% 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"
    },
    {
      divider: "or"
    },
    {
      value: "abroad",
      text: "I am a British citizen living abroad"
    }
  ]
}) }}

Conditionally revealing content

Using this component, you can add conditionally revealing content to stacked 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" aria-describedby="how-contacted-conditional-hint">
    <legend class="govuk-fieldset__legend govuk-fieldset__legend--xl">
      <h1 class="govuk-fieldset__heading">
        How would you prefer to be contacted?
      </h1>
    </legend>
    <span id="how-contacted-conditional-hint" class="govuk-hint">
      Select one option.
    </span>
    <div class="govuk-radios govuk-radios--conditional" 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 govuk-radios__conditional--hidden" 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="email">
        </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 govuk-radios__conditional--hidden" 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="tel">
        </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 govuk-radios__conditional--hidden" 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="tel">
        </div>

      </div>
    </div>
  </fieldset>
</div>
Nunjucks macro options

Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.

Some options are required for the macro to work; these are marked as "Required" in the option description.

If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against cross-site scripting exploits.

Primary options
Name Type Description
fieldset object Options for the fieldset component (e.g. legend). See fieldset.
hint object Options for the hint component (e.g. text). See hint.
errorMessage object Options for the errorMessage component (e.g. text). See errorMessage.
formGroup object Options for the form-group wrapper See formGroup.
idPrefix string String to prefix id for each checkbox item if no id is specified on each item. If idPrefix is not passed, fallback to using the name attribute instead.
name string Required. Name attribute for each radio item.
items array Required. Array of radio items objects. See items.
classes string Classes to add to the radio container.
attributes object HTML attributes (for example data attributes) to add to the radio input tag.
Options for formGroup
Name Type Description
classes string Optional classes to add to the form group (e.g. to show error state for the whole group)
Options for items
Name Type Description
text string Required. If html is set, this is not required. Text to use within each radio item label. If html is provided, the text argument will be ignored.
html string Required. If text is set, this is not required. HTML to use within each radio item label. If html is provided, the text argument will be ignored.
id string Specific id attribute for the radio item. If omitted, then idPrefix string will be applied.
name string Required. Specific name for the radio item. If omitted, then component global name string will be applied.
value string Required. Value for the radio input.
label object Provide attributes and classes to each radio item label. See label.
hint object Provide hint to each checkbox item. See hint.
divider string Divider text to separate radio items, for example the text "or".
checked boolean If true, radio will be checked.
conditional string If true, content provided will be revealed when the item is checked.
conditional.html html Provide content for the conditional reveal.
disabled boolean If true, radio will be disabled.
attributes object HTML attributes (for example data attributes) to add to the radio input tag.
Options for hint
Name Type Description
text string Required. If `html` is set, this is not required. Text to use within the hint. If `html` is provided, the `text` argument will be ignored.
html string Required. If `text` is set, this is not required. HTML to use within the hint. If `html` is provided, the `text` argument will be ignored.
id string Required. Optional id attribute to add to the hint span tag.
classes string Classes to add to the hint span tag.
attributes object HTML attributes (for example data attributes) to add to the hint span tag.
Options for label
Name Type Description
text string Required. If `html` is set, this is not required. Text to use within the label. If `html` is provided, the `text` argument will be ignored.
html string Required. If `text` is set, this is not required. HTML to use within the label. If `html` is provided, the `text` argument will be ignored.
for string Required. The value of the for attribute, the id of the input the label is associated with.
isPageHeading boolean Whether the label also acts as the heading for the page.
classes string Classes to add to the label tag.
attributes object HTML attributes (for example data attributes) to add to the label tag.
{% from "radios/macro.njk" import govukRadios %}
{% from "input/macro.njk" import govukInput %}

{% set emailHtml %}
{{ govukInput({
  id: "contact-by-email",
  name: "contact-by-email",
  type: "email",
  classes: "govuk-!-width-one-third",
  label: {
    text: "Email address"
  }
}) }}
{% endset -%}

{% set phoneHtml %}
{{ govukInput({
  id: "contact-by-phone",
  name: "contact-by-phone",
  type: "tel",
  classes: "govuk-!-width-one-third",
  label: {
    text: "Phone number"
  }
}) }}
{% endset -%}

{% set textHtml %}
{{ govukInput({
  id: "contact-by-text",
  name: "contact-by-text",
  type: "tel",
  classes: "govuk-!-width-one-third",
  label: {
    text: "Mobile phone number"
  }
}) }}
{% endset -%}

{{ govukRadios({
  idPrefix: "how-contacted-conditional",
  name: "how-contacted",
  fieldset: {
    legend: {
      text: "How would you prefer to be contacted?",
      isPageHeading: true,
      classes: "govuk-fieldset__legend--xl"
    }
  },
  hint: {
    text: "Select one option."
  },
  items: [
    {
      value: "email",
      text: "Email",
      conditional: {
        html: emailHtml
      }
    },
    {
      value: "phone",
      text: "Phone",
      conditional: {
        html: phoneHtml
      }
    },
    {
      value: "text",
      text: "Text message",
      conditional: {
        html: textHtml
      }
    }
  ]
}) }}

Keep it simple. If you need to add a lot of content, consider showing it on the next page in the process instead.

Do not use this component to add conditionally revealing content to inline radios.

Error messages

Error messages should be styled like this:

<div class="govuk-form-group govuk-form-group--error">
  <fieldset class="govuk-fieldset" aria-describedby="changed-name-hint changed-name-error">
    <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>
    <span id="changed-name-error" class="govuk-error-message">
      Select yes if you have changed your name
    </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>
Nunjucks macro options

Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.

Some options are required for the macro to work; these are marked as "Required" in the option description.

If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against cross-site scripting exploits.

Primary options
Name Type Description
fieldset object Options for the fieldset component (e.g. legend). See fieldset.
hint object Options for the hint component (e.g. text). See hint.
errorMessage object Options for the errorMessage component (e.g. text). See errorMessage.
formGroup object Options for the form-group wrapper See formGroup.
idPrefix string String to prefix id for each checkbox item if no id is specified on each item. If idPrefix is not passed, fallback to using the name attribute instead.
name string Required. Name attribute for each radio item.
items array Required. Array of radio items objects. See items.
classes string Classes to add to the radio container.
attributes object HTML attributes (for example data attributes) to add to the radio input tag.
Options for formGroup
Name Type Description
classes string Optional classes to add to the form group (e.g. to show error state for the whole group)
Options for items
Name Type Description
text string Required. If html is set, this is not required. Text to use within each radio item label. If html is provided, the text argument will be ignored.
html string Required. If text is set, this is not required. HTML to use within each radio item label. If html is provided, the text argument will be ignored.
id string Specific id attribute for the radio item. If omitted, then idPrefix string will be applied.
name string Required. Specific name for the radio item. If omitted, then component global name string will be applied.
value string Required. Value for the radio input.
label object Provide attributes and classes to each radio item label. See label.
hint object Provide hint to each checkbox item. See hint.
divider string Divider text to separate radio items, for example the text "or".
checked boolean If true, radio will be checked.
conditional string If true, content provided will be revealed when the item is checked.
conditional.html html Provide content for the conditional reveal.
disabled boolean If true, radio will be disabled.
attributes object HTML attributes (for example data attributes) to add to the radio input tag.
Options for hint
Name Type Description
text string Required. If `html` is set, this is not required. Text to use within the hint. If `html` is provided, the `text` argument will be ignored.
html string Required. If `text` is set, this is not required. HTML to use within the hint. If `html` is provided, the `text` argument will be ignored.
id string Required. Optional id attribute to add to the hint span tag.
classes string Classes to add to the hint span tag.
attributes object HTML attributes (for example data attributes) to add to the hint span tag.
Options for label
Name Type Description
text string Required. If `html` is set, this is not required. Text to use within the label. If `html` is provided, the `text` argument will be ignored.
html string Required. If `text` is set, this is not required. HTML to use within the label. If `html` is provided, the `text` argument will be ignored.
for string Required. The value of the for attribute, the id of the input the label is associated with.
isPageHeading boolean Whether the label also acts as the heading for the page.
classes string Classes to add to the label tag.
attributes object HTML attributes (for example data attributes) to add to the label tag.
{% 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."
  },
  errorMessage: {
    text: "Select yes if you have changed your name"
  },
  items: [
    {
      value: "yes",
      text: "Yes"
    },
    {
      value: "no",
      text: "No"
    }
  ]
}) }}

Make sure errors follow the guidance in error message and have specific error messages for specific error states.

If nothing is selected and the options are ‘yes’ and ‘no’

Say ‘Select yes if [whatever it is is true]’.
For example, ‘Select yes if Sarah normally lives with you’.

If nothing is selected and the question has options in it

Say ‘Select if [whatever it is]’.
For example, ‘Select if you are employed or self-employed’.

If nothing is selected and the question does not have options in it

Say ‘Select [whatever it is]’.
For example, ‘Select the day of the week you pay your rent’.

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 on govuk-design-system-support@digital.cabinet-office.gov.uk

Discuss ‘Radios’ on GitHub