HTML <legend> Tag
To insert a title or caption to the <fieldset> tag, the HTML <legend> tag is used. For this, the first child of the HTML <fieldset> tag should be the HTML <legend> tag. Thus understanding the purpose of the grouped form elements becomes easy.
Syntax:
<legend>Content<legend>
Example:
<!DOCTYPE html> <html> <body> <form> <fieldset> <legend>Subject Details:</legend> Name: <input type="text"><br><br> Subject: <input type="text"><br><br> Faculty Name: <input type="text"> </fieldset> </form> </body> </html>
Explanation:
In the above example, we have used the <legend> tag to add a title to the <fieldset> tag.
Tag Specific Attributes:
Attribute | Value | Uses | |
align | top
bottom left right |
Used to define the caption alignment. | Not Supported in HTML5. |
Global Attributes:
The HTML Global attributes are supported by the HTML <legend> tag.
Event Attributes:
The HTML Event attributes are supported by the HTML <legend> tag.
Supporting Browsers:
Chrome, IE, Firefox, Opera, and Safari.