Skip to the page
html reference · forms

HTML <fieldset> / <legend> tags

closing tag
required (both)
void element
no
lives inside
<form>
typically holds
a <legend>, then a group of related fields

Where it goes

Inside a <form>, around fields that belong together: a group of radio buttons, a shipping address. <legend> goes first inside it.

Example

<fieldset>
  <legend>Size</legend>
  <input type="radio" name="size" id="s"> <label for="s">Small</label>
  <input type="radio" name="size" id="m"> <label for="m">Medium</label>
</fieldset>

Open this example in the editor →

Common mistakes

  • Grouping radio buttons with just a heading above them. A heading is not attached to the fields. Only <legend> inside <fieldset> is read with each option.
  • Putting <legend> anywhere but first inside the <fieldset>. It only works as the first thing.
  • Wrapping the whole form in one <fieldset>. It is for a subgroup. One giant group adds a border and a title but no useful structure.

Related

Updated 24 October 2026. Practice it in the html route, or read more on MDN.