<fieldsetclass="govuk-fieldset"><legendclass="govuk-fieldset__legend">
My fieldset
</legend>
Content
</fieldset>
<FieldSetlegend="My fieldset">Content</FieldSet>
Props
Name
Type
Default
Description
id
string
-
'id' attribute to place on the base HTML element
classBlock
string
-
Block name override in BEM style classes applied to all elements
classModifiers
Modifiers
-
BEM style modifiers to apply to the base HTML element
className
string
-
Extra classes to apply to the base HTML element
legend
ReactNode
-
REQUIRED.
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.
<fieldsetclass="govuk-fieldset"><legendclass="govuk-fieldset__legend"><h1class="govuk-heading-l">
What is your address?
</h1></legend><divclass="govuk-form-group"><labelclass="govuk-label"aria-hidden="false">
Building and street
<spanclass="govuk-visually-hidden">
line 2 of 2
</span></label><inputautocomplete="address-line1"class="govuk-input"type="text"name="address-line1"/></div><divclass="govuk-form-group"><labelclass="govuk-label"aria-hidden="false"><spanclass="govuk-visually-hidden">
Building and street line 2 of 2
</span></label><inputautocomplete="address-line2"class="govuk-input"type="text"name="address-line2"/></div><divclass="govuk-form-group"><labelclass="govuk-label"aria-hidden="false">
Town or city
</label><inputautocomplete="address-town"class="govuk-input govuk-!-width-two-thirds"type="text"name="address-town"/></div><divclass="govuk-form-group"><labelclass="govuk-label"aria-hidden="false">
County
</label><inputautocomplete="address-county"class="govuk-input govuk-!-width-two-thirds"type="text"name="address-county"/></div><divclass="govuk-form-group"><labelclass="govuk-label"aria-hidden="false">
Postcode
</label><inputautocomplete="address-postcode"class="govuk-input"style="max-width:22.86ex"type="text"name="address-postcode"/></div></fieldset>
<FieldSetlegend={<h1className="govuk-heading-l">
What is your address?
</h1>}><divclassName="govuk-form-group"><Label>
Building and street{" "}<VisuallyHidden>line 2 of 2</VisuallyHidden></Label><InputautoComplete="address-line1"name="address-line1"/></div><divclassName="govuk-form-group"><Label><VisuallyHidden>
Building and street line 2 of 2
</VisuallyHidden></Label><InputautoComplete="address-line2"name="address-line2"/></div><divclassName="govuk-form-group"><Label>Town or city</Label><InputautoComplete="address-town"className="govuk-!-width-two-thirds"name="address-town"/></div><divclassName="govuk-form-group"><Label>County</Label><InputautoComplete="address-county"className="govuk-!-width-two-thirds"name="address-county"/></div><divclassName="govuk-form-group"><Label>Postcode</Label><InputautoComplete="address-postcode"name="address-postcode"width={10}/></div></FieldSet>
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.
<fieldsetclass="govuk-fieldset"><legendclass="govuk-fieldset__legend"><h1class="govuk-heading-l">
Legend as page heading
</h1></legend></fieldset>
<FieldSetlegend={<h1className="govuk-heading-l">
Legend as page heading
</h1>}/>
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 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.