Components

FieldSet

Use the fieldset component to group related form inputs.

My fieldsetContent
Props
NameTypeDefaultDescription
idstring-'id' attribute to place on the base HTML element
classBlockstring-Block name override in BEM style classes applied to all elements
classModifiersModifiers-BEM style modifiers to apply to the base HTML element
classNamestring-Extra classes to apply to the base HTML element
legendReactNode-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.

What is your address?

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.

Legend as page heading

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.