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:

HTML/XHTML: <legend> ... </legend>

The example below shows the <legend> tag in action.

<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.

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

Element
<legend>YesYesYesYesYes