HTML <legend> Tag

By Jonathan Griffin. Editor, SEO Consultant, & Developer.

· 1 min read

Definition

The <legend> tag displays a caption for the parent <fieldset> element.

Example

<form>
  <fieldset>
    <legend>What is your favorite programming language</legend>

    <input type="radio" id="javascript" name="language">
    <label for="javascript">JavaScript</label><br/>

    <input type="radio" id="python" name="language">
    <label for="python">Python</label><br/>

    <input type="radio" id="golang" name="language">
    <label for="golang">Golang</label>
  </fieldset>
</form>

Usage

  • The <legend> element must be the first child of a <fieldset> element.
  • An opening and closing tag is required.

Attributes

The <legend> element only supports the Global Attributes.

Best Practices

  • It is good practice to organize form fields into <fieldset> groups with appropriate legends. This makes forms much easier to use.

Specification

Browser Support

Desktop

ChromeEdgeFirefoxIEOperaSafari
YesYesYesYesYesYes

Mobile

Android WebviewChrome AndroidFirefox AndroidOpera AndroidiOS SafariSamsung Internet
YesYesYesYesYesYes