Forms & Controls

HTML <legend> element

Supplies a caption for a fieldset group. Place it as the first child of the fieldset when labeling the group. A legend supplies context to the controls within its fieldset, which is useful for radio or checkbox groups. Keep the legend concise so it is not repeatedly announced as a lengthy instruction. It accepts global HTML attributes; individual global features may be inapplicable or restricted.

Formal Syntax & Structure

html syntaxhtml
<legend>Group caption</legend>

Return Value

HTMLLegendElement

Content model: Phrasing content and headings in fieldset; other contexts have separate rules.

Working Example

Example Snippethtml
<!doctype html><html lang="en">  <head>    <meta charset="utf-8">    <title>HTML example</title>  </head>  <body>    <fieldset>      <legend>Preferences</legend>      <label>        <input type="checkbox" name="updates">        Updates      </label>    </fieldset>  </body></html>
HTML Reference