HTML: fieldset

The <fieldset> element groups related form controls, while <legend> gives the group a name.

What you will learn

Radio button group

<fieldset>
  <legend>Preferred contact method</legend>
  <label><input type="radio" name="contact" value="email"> Email</label>
  <label><input type="radio" name="contact" value="phone"> Phone</label>
</fieldset>

The legend explains what the choices have in common. The shared name makes the radio buttons one choice group.

When to use it

Use fieldset for related checkboxes, radio buttons, address sections, or other controls that form one logical group. It provides structure for both visual users and assistive technology.

Common mistakes