HTML <legend> Tag
Topic: HTML5 Tags ReferencePrev|Next
Description
The <legend> tag is used to assign a caption to a set of form controls defined by the <fieldset> element.
The following table summarizes the usages context and the version history of this tag.
| Parent: | <fieldset> |
|---|---|
| Placement: | Inline |
| Content: | Inline and text |
| Start/End Tag: | Start tag: required, End tag: required |
| Version: | HTML 2, 3.2, 4, 4.01, 5 |
Syntax
The basic syntax of the <legend> tag is given with:
The example below shows the <legend> tag in action.
Example
Try this code »<form action="http://www.example.com/" method="post">
<fieldset>
<legend>Gender</legend>
<input type="radio" name="gender" value="male" id="male">
<label for="male">Male</label>
<input type="radio" name="gender" value="female" id="female">
<label for="female">Female</label>
</fieldset>
</form>
Tag-Specific Attributes
The following table shows the attributes that are specific to the <legend> tag.
| Attribute | Value | Description |
|---|---|---|
align |
top |
Obsolete Specifies the alignment or position of the caption text with respect to the fieldset. |
Global Attributes
Like all other HTML tags, the <legend> tag supports the global attributes in HTML5.
Event Attributes
The <legend> tag also supports the event attributes in HTML5.
Browser Compatibility
The <legend> tag is supported in all major modern browsers.
Basic Support—
|
Further Reading
See tutorial on: HTML Forms.
Other form-related tags: <form>, <fieldset>, <label>, <input>, <textarea>, <select>, <optgroup>, <option>, <button>.

