Fieldsets
Best practices
Use fieldsets and labels (legend
tags) to group and describe a set of controls and/or fields within a form. These should be grouped to help users understand what is required of them in a logical way. Try to make the headline concise and informative, but where needed, you can add a short paragraph of text to explain the group.
When to use a fieldset and legend
Use the <fieldset>
and <legend>
elements when you have:
- A single multiple choice question (using radio buttons or checkboxes).
- Several questions relating to the same topic (like text boxes, or any other type of field).
When not to use a fieldset and legend
Do not use the <fieldset>
and <legend>
when you have:
- A single form field that asks for a single piece of information.
When used correctly, the <fieldset>
and <legend>
elements tie related form fields together in a way that is accessible to people who cannot see the visual layout of the form.
How it works
For an example of fieldsets with several questions relating to the same topic, see our name and address form example.