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
Chrome | Edge | Firefox | IE | Opera | Safari |
---|---|---|---|---|---|
Yes | Yes | Yes | Yes | Yes | Yes |
Mobile
Android Webview | Chrome Android | Firefox Android | Opera Android | iOS Safari | Samsung Internet |
---|---|---|---|---|---|
Yes | Yes | Yes | Yes | Yes | Yes |