Description
The HTML element <legend>
is used to define a title or caption to a set of form control elements, defined using the <fieldset>
element.
The below table summarizes its usage.
Usage Details | |
Parent Element | <fieldset> |
Placement | It is displayed as an Inline element. |
Contents | It can contain Inline elements and text. |
Tags | Both opening and closing tags are required. |
Versions | HTML 2, 3.2, 4, 4.01, 5 |
Syntax
Here is the basic syntax of the <legend>
element.
<legend>...</legend>
Examples
In the below example, the <legend>
element is used to define a title to the <fieldset>
element.
<!DOCTYPE html>
<html lang="en">
<head>
<title>HTML Element - legend</title>
</head>
<body>
<form action="http://www.example.com/" method="post">
<fieldset>
<legend>User Details</legend>
<label for="name">Name:</label>
<input type="text" id="name" name="name"><br><br>
<label>Email: <input type="email" id="email" name="email"></label>
</fieldset>
</form>
</body>
</html>
Attributes
The following table shows the list of supported and unsupported attributes for the <legend>
element.
Attribute Type | Details |
Element-Specific Attributes | The tags <legend> has some element-specific attributes listed in the below table. |
Global Attributes | Like all other HTML tags, the tag <legend> supports the HTML Global Attributes. |
Event Attributes | The tags <legend> also supports the HTML Event Attributes. |
Here is a list of attributes that are specific to the <legend>
element.
Attribute | Value | Description |
align |
top |
Obsolete Specifies the alignment or position of the title or caption text with respect to the fieldset. |
Browser Compatibility
The tags <legend>
is supported in all modern browsers.
- Google Chrome 1+
- Internet Explorer or Edge 4+
- Firefox 1+
- Apple Safari 1+
- Opera 4+