Components Checkboxes

Let users select one or more options by using the checkboxes component.

<div class="govuk-form-group">
  <fieldset class="govuk-fieldset" aria-describedby="nationality-hint">
    <legend class="govuk-fieldset__legend govuk-fieldset__legend--xl">
      <h1 class="govuk-fieldset__heading">
        What is your nationality?
      </h1>
    </legend>
    <span id="nationality-hint" class="govuk-hint">
    If you have dual nationality, select all options that are relevant to you.
  </span>
    <div class="govuk-checkboxes">
      <div class="govuk-checkboxes__item">
        <input class="govuk-checkboxes__input" id="nationality-1" name="nationality" type="checkbox" value="british">
        <label class="govuk-label govuk-checkboxes__label" for="nationality-1">
        British
      </label>
      </div>
      <div class="govuk-checkboxes__item">
        <input class="govuk-checkboxes__input" id="nationality-2" name="nationality" type="checkbox" value="irish">
        <label class="govuk-label govuk-checkboxes__label" for="nationality-2">
        Irish
      </label>
      </div>
      <div class="govuk-checkboxes__item">
        <input class="govuk-checkboxes__input" id="nationality-3" name="nationality" type="checkbox" value="other">
        <label class="govuk-label govuk-checkboxes__label" for="nationality-3">
        Citizen of another country
      </label>
      </div>
    </div>
  </fieldset>
</div>
{% from "checkboxes/macro.njk" import govukCheckboxes %}

{{ govukCheckboxes({
  idPrefix: "nationality",
  name: "nationality",
  fieldset: {
    legend: {
      text: "What is your nationality?",
      isPageHeading: true,
      classes: "govuk-fieldset__legend--xl"
    }
  },
  hint: {
    text: "If you have dual nationality, select all options that are relevant to you."
  },
  items: [
    {
      value: "british",
      text: "British"
    },
    {
      value: "irish",
      text: "Irish"
    },
    {
      value: "other",
      text: "Citizen of another country"
    }
  ]
}) }}

You can configure this component using the Nunjucks macro arguments.

When to use this component

Use the checkboxes component when you need to help users:

  • select multiple options from a list
  • toggle a single option on or off

When not to use this component

Don’t use the checkboxes component if users can only choose one option from a selection. In this case, use the radios component.

How it works

There are 2 ways to use the checkboxes component. You can use HTML or, if you’re using Nunjucks or the GOV.UK Prototype Kit, you can use the Nunjucks macro.

<div class="govuk-form-group">
  <fieldset class="govuk-fieldset" aria-describedby="nationality-hint">
    <legend class="govuk-fieldset__legend govuk-fieldset__legend--xl">
      <h1 class="govuk-fieldset__heading">
        What is your nationality?
      </h1>
    </legend>
    <span id="nationality-hint" class="govuk-hint">
    If you have dual nationality, select all options that are relevant to you.
  </span>
    <div class="govuk-checkboxes">
      <div class="govuk-checkboxes__item">
        <input class="govuk-checkboxes__input" id="nationality-1" name="nationality" type="checkbox" value="british">
        <label class="govuk-label govuk-checkboxes__label" for="nationality-1">
        British
      </label>
      </div>
      <div class="govuk-checkboxes__item">
        <input class="govuk-checkboxes__input" id="nationality-2" name="nationality" type="checkbox" value="irish">
        <label class="govuk-label govuk-checkboxes__label" for="nationality-2">
        Irish
      </label>
      </div>
      <div class="govuk-checkboxes__item">
        <input class="govuk-checkboxes__input" id="nationality-3" name="nationality" type="checkbox" value="other">
        <label class="govuk-label govuk-checkboxes__label" for="nationality-3">
        Citizen of another country
      </label>
      </div>
    </div>
  </fieldset>
</div>
{% from "checkboxes/macro.njk" import govukCheckboxes %}

{{ govukCheckboxes({
  idPrefix: "nationality",
  name: "nationality",
  fieldset: {
    legend: {
      text: "What is your nationality?",
      isPageHeading: true,
      classes: "govuk-fieldset__legend--xl"
    }
  },
  hint: {
    text: "If you have dual nationality, select all options that are relevant to you."
  },
  items: [
    {
      value: "british",
      text: "British"
    },
    {
      value: "irish",
      text: "Irish"
    },
    {
      value: "other",
      text: "Citizen of another country"
    }
  ]
}) }}

You can configure this component using the Nunjucks macro arguments.

Conditionally revealing content

You can add conditionally revealing content to checkboxes, so users only see content when it’s relevant to them. For example, you could reveal a phone number input only when a user chooses to be contacted by phone.

<div class="govuk-form-group">
  <fieldset class="govuk-fieldset">
    <legend class="govuk-fieldset__legend govuk-fieldset__legend--m">
      <h1 class="govuk-fieldset__heading">
        How would you like to be contacted?
      </h1>
    </legend>
    <div class="govuk-checkboxes" data-module="checkboxes">
      <div class="govuk-checkboxes__item">
        <input class="govuk-checkboxes__input" id="citizenship-conditional-1" name="citizen" type="checkbox" value="email" data-aria-controls="conditional-citizenship-conditional-1">
        <label class="govuk-label govuk-checkboxes__label" for="citizenship-conditional-1">
        Email
      </label>
      </div>
      <div class="govuk-checkboxes__conditional" id="conditional-citizenship-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-checkboxes__item">
        <input class="govuk-checkboxes__input" id="citizenship-conditional-2" name="citizen" type="checkbox" value="phone" data-aria-controls="conditional-citizenship-conditional-2">
        <label class="govuk-label govuk-checkboxes__label" for="citizenship-conditional-2">
        Phone
      </label>
      </div>
      <div class="govuk-checkboxes__conditional" id="conditional-citizenship-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-checkboxes__item">
        <input class="govuk-checkboxes__input" id="citizenship-conditional-3" name="citizen" type="checkbox" value="text message" data-aria-controls="conditional-citizenship-conditional-3">
        <label class="govuk-label govuk-checkboxes__label" for="citizenship-conditional-3">
        Text message
      </label>
      </div>
      <div class="govuk-checkboxes__conditional" id="conditional-citizenship-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 "checkboxes/macro.njk" import govukCheckboxes %}
{% 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 -%}

{{ govukCheckboxes({
  idPrefix: "citizenship-conditional",
  name: "citizen",
  fieldset: {
    legend: {
      text: "How would you like to be contacted?",
      isPageHeading: true,
      classes: "govuk-fieldset__legend--m"
    },
    hint: {
      text: "Select all options that are relevant to you."
    }
  },
  items: [
    {
      value: "email",
      text: "Email",
      conditional: {
        html: emailHtml
      }
    },
    {
      value: "phone",
      text: "Phone",
      conditional: {
        html: phoneHtml
      }
    },
    {
      value: "text message",
      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 on govuk-design-system-support@digital.cabinet-office.gov.uk

Discuss ‘Checkboxes’ on GitHub