Fieldset

Use a fieldset to group related form inputs.

Code and design

Fieldset

Open in new window
Copy
<fieldset class="nhsuk-fieldset">
  <legend class="nhsuk-fieldset__legend">
    What is your address?
  </legend>
</fieldset>
Copy
{% from 'fieldset/macro.njk' import fieldset %}

{{ fieldset({
  "legend": {
    "text": "What is your address?"
  }
}) }}

Fieldset as page heading

Open in new window
Copy
<fieldset class="nhsuk-fieldset">
  <legend class="nhsuk-fieldset__legend nhsuk-fieldset__legend--xl">
    <h1 class="nhsuk-fieldset__heading">
      What is your address?
    </h1>
  </legend>
</fieldset>
Copy
{% from 'fieldset/macro.njk' import fieldset %}

{{ fieldset({
  "legend": {
    "text": "What is your address?",
    "classes": "nhsuk-fieldset__legend--xl",
    "isPageHeading": true
  }
}) }}

When to use a fieldset

Use a fieldset when you need to show a relationship between multiple form inputs. For example, you may need to group a set of text inputs into a single fieldset when asking for an address.

How to use a fieldset

The first element in a fieldset must be a legend which describes the group of inputs. This could be a question, such as "What is your current address?" or a statement like "Personal details".

If you’re asking just 1 question per page, as recommended by the GOV.UK design system, you can set the contents of the <legend> as the page heading. You can see an example at the top of this page. This is good practice as it means that users of screen readers will only hear the contents once.

Read more about why and how the GOV.UK design system sets legends as headings.

Accessibility

On question pages containing a group of inputs, include the question as the legend as that helps screenreader users understand that the inputs are all related to that question.

Include any general help text which is important for filling in the form and cannot be written as hint text in the legend, but try to keep it as concise as possible.

Research

If you’ve used this component, get in touch to share your user research findings.

Discuss

Discuss fieldsets on GitHub

Get in touch

If you have a question:

Updated: January 2019