Fieldset
Use the fieldset component to group related form inputs.
When to use this component
Use the fieldset component 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.
<fieldset class="govuk-fieldset">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--l">
<h1 class="govuk-fieldset__heading">
What is your address?
</h1>
</legend>
<div class="govuk-form-group">
<label class="govuk-label" for="address-line-1">
Address line 1
</label>
<input class="govuk-input" id="address-line-1" name="addressLine1" type="text" autocomplete="address-line1">
</div>
<div class="govuk-form-group">
<label class="govuk-label" for="address-line-2">
Address line 2 (optional)
</label>
<input class="govuk-input" id="address-line-2" name="addressLine2" type="text" autocomplete="address-line2">
</div>
<div class="govuk-form-group">
<label class="govuk-label" for="address-town">
Town or city
</label>
<input class="govuk-input govuk-!-width-two-thirds" id="address-town" name="addressTown" type="text" autocomplete="address-level2">
</div>
<div class="govuk-form-group">
<label class="govuk-label" for="address-postcode">
Postcode
</label>
<input class="govuk-input govuk-input--width-10" id="address-postcode" name="addressPostcode" type="text" autocomplete="postal-code">
</div>
</fieldset>
{% from "govuk/components/input/macro.njk" import govukInput %}
{% from "govuk/components/fieldset/macro.njk" import govukFieldset %}
{% call govukFieldset({
legend: {
text: "What is your address?",
classes: "govuk-fieldset__legend--l",
isPageHeading: true
}
}) %}
{{ govukInput({
label: {
text: "Address line 1"
},
id: "address-line-1",
name: "addressLine1",
autocomplete: "address-line1"
}) }}
{{ govukInput({
label: {
text: "Address line 2 (optional)"
},
id: "address-line-2",
name: "addressLine2",
autocomplete: "address-line2"
}) }}
{{ govukInput({
label: {
text: "Town or city"
},
classes: "govuk-!-width-two-thirds",
id: "address-town",
name: "addressTown",
autocomplete: "address-level2"
}) }}
{{ govukInput({
label: {
text: "Postcode"
},
classes: "govuk-input--width-10",
id: "address-postcode",
name: "addressPostcode",
autocomplete: "postal-code"
}) }}
{% endcall %}
If you’re using the examples or macros for radios, checkboxes or date input, the fieldset will already be included.
How it works
The first element inside 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 one question per page as recommended, you can set the contents of the <legend>
as the page heading, as shown in the example below. 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.
<fieldset class="govuk-fieldset">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--l">
<h1 class="govuk-fieldset__heading">
Legend as page heading
</h1>
</legend>
</fieldset>
{% from "govuk/components/fieldset/macro.njk" import govukFieldset %}
{{ govukFieldset({
legend: {
text: "Legend as page heading",
classes: "govuk-fieldset__legend--l",
isPageHeading: true
}
}) }}
On question pages containing a group of inputs, including the question as the legend helps users of screen readers to understand that the inputs are all related to that question.
Include general help text in the legend if it would help the user fill in the form, and you cannot write it as hint text. However, try to keep it as short as possible.
Help improve this component
To help make sure that this page is useful, relevant and up to date, you can:
- take part in the ‘Fieldset’ discussion on GitHub and share your research
- propose a change – read more about how to propose changes in GitHub
Tell us if your service uses this component
Take part in our usage survey (opens in a new tab) to help us improve this component to better meet the needs of the services that use it.
Need help?
If you’ve got a question about the GOV.UK Design System, contact the team.