Form fieldset
The fieldset element is used to group several controls within a web form. The legend element represents a caption for the content of its parent fieldset.
Using the fieldset and legend elements
You can use the text
property or pass text
as a block.
How it looks (preview) (preview all)
How to call this component
<%= render "govuk_publishing_components/components/fieldset", {
legend_text: "Do you have a passport?"
} do %>
<!-- example content -->
<%= render "govuk_publishing_components/components/radio", {
name: "default",
items: [
{
value: "default-yes",
text: "Yes"
},
{
value: "default-no",
text: "No"
}
]
} %>
<!-- end of example content -->
<% end %>
Accessibility acceptance criteria
- must give inputs within the fieldset context with legend text
Other examples
Standard options
This component uses the component wrapper helper. It accepts the following options and applies them to the parent element of the component. See the component wrapper helper documentation for more detail.
id
- accepts a string for the element ID attributedata_attributes
- accepts a hash of data attributesaria
- accepts a hash of aria attributesclasses
- accepts a space separated string of classes, these should not be used for styling and must be prefixed withjs-
margin_bottom
- accepts a number from0
to9
(0px
to60px
) using the GOV.UK Frontend spacing scale (defaults to no margin)role
- accepts a space separated string of roleslang
- accepts a language attribute valueopen
- accepts an open attribute value (true or false)hidden
- accepts an empty string, ‘hidden’, or ‘until-found’tabindex
- accepts an integer. The integer can also be passed as a string.dir
- accepts ‘rtl’, ‘ltr’, or ‘auto’.
With id attribute (preview)
<%= render "govuk_publishing_components/components/fieldset", {
legend_text: "Do you have a passport?",
id: "passports"
} do %>
<!-- example content -->
<%= render "govuk_publishing_components/components/radio", {
name: "passport",
items: [
{
value: "passport-yes",
text: "Yes"
},
{
value: "passport-no",
text: "No"
}
]
} %>
<!-- end of example content -->
<% end %>
With heading (preview)
Make the legend different sizes. Valid options are s
, m
, l
and xl
.
<%= render "govuk_publishing_components/components/fieldset", {
legend_text: "Do you have a driving license?",
heading_level: 2,
heading_size: "m"
} do %>
<!-- example content -->
<%= render "govuk_publishing_components/components/radio", {
name: "level",
items: [
{
value: "level-yes",
text: "Yes"
},
{
value: "level-no",
text: "No"
}
]
} %>
<!-- end of example content -->
<% end %>
With custom legend size (preview)
Make the legend different sizes. Valid options are s
, m
, l
and xl
.
<%= render "govuk_publishing_components/components/fieldset", {
legend_text: "Do you have a driving license?",
heading_size: "l"
} do %>
<!-- example content -->
<%= render "govuk_publishing_components/components/radio", {
name: "size",
items: [
{
value: "size-yes",
text: "Yes"
},
{
value: "size-no",
text: "No"
}
]
} %>
<!-- end of example content -->
<% end %>
With error message (preview)
The component also accepts an error_id
, or generates one automatically.
<%= render "govuk_publishing_components/components/fieldset", {
legend_text: "Do you have a passport?",
error_message: "Please choose an option"
} do %>
<!-- example content -->
<%= render "govuk_publishing_components/components/radio", {
name: "default2",
items: [
{
value: "default2-yes",
text: "Yes"
},
{
value: "default2-no",
text: "No"
}
]
} %>
<!-- end of example content -->
<% end %>