freecoding.school100% FREE · NO SIGNUP
Input HarborISSUE #11 of 46

fieldset · legend · grouping inputs

FormaVSCaptain Invalid Input
Forma says<fieldset> groups related controls and <legend> titles the group — structure that helps everyone, especially screen readers.

Wrap related controls in a <fieldset> and give it a <legend> caption. Visually it draws a labeled border; semantically it tells assistive tech "these inputs belong together" (essential for radio-button groups).

Use fieldsets for sections of a long form — "Shipping address", "Payment" — so the form reads as organized chunks rather than an undifferentiated wall of inputs.

Power-ups you unlock

Captain Invalid Input attacks — common mistakes

Boss battleGroup a set of "contact method" radios inside a fieldset with a legend, so the question is announced with each option.

Example code

<!doctype html>
<html><head><meta charset="utf-8">
<style>fieldset{border:1px solid #2a1d4a;border-radius:6px}legend{color:#b388ff}</style>
</head>
<body style="background:#06040d;color:#e6e0ff;font-family:sans-serif;padding:20px">
  <form action="#">
    <fieldset>
      <legend>preferred contact</legend>
      <label><input type="radio" name="c" value="email"> email</label>
      <label><input type="radio" name="c" value="phone"> phone</label>
    </fieldset>
  </form>
</body></html>
▶ Open the interactive comic issue
‹ Autocomplete · How The Browser RemembersLabels · For · Id · Accessibility ›