The HTML <legend> tag
The HTML <legend> element provides a caption for its parent <fieldset>. It must be the fieldset's first child and names the group of controls for assistive technology.
Overview
The <legend> element captions a <fieldset>, and it must be the fieldset's first child. Visually it appears as the group's title, usually sitting on the fieldset's top border.
Its real value is for accessibility. The legend gives the grouped controls a shared accessible name, which is exactly what makes a set of radio buttons understandable: screen readers pair the legend's question with each option, so users hear "Shipping method, Standard" rather than just "Standard" with no context.
Syntax
<fieldset>
<legend>Shipping address</legend>
…
</fieldset>
Example
<fieldset style="border:1px solid #cbd5e1;border-radius:6px;">
<legend>Account type</legend>
<label><input type="radio" name="a"> Personal</label>
<label><input type="radio" name="a"> Business</label>
</fieldset>
Best practices
- Make the
<legend>the very first child of its <fieldset>. - Keep it concise; it is read alongside every control in the group.
- Treat it as the question for a radio or checkbox group, with each control as an answer.
- Restyle its default position and appearance with CSS as needed.























