In this section, we will learn what HTML <legend> element is and how to use it.
What is <legend> Tag in HTML?
We use HTML <legend> element to create a caption for an HTML <fieldset> element that is its parent (The <legend> element sits inside the body of the <fieldset> element).
Note: you can learn more about HTML <fieldset> element in its section but in short, this element is used in an HTML <form> element to group a set of related form fields together and also browsers render an HTML <fieldset> element as a line around that grouped fields. Now using HTML <legend> element, we can set a caption for this group of fields in a form.
HTML <legend> Tag Syntax:
<legend> Caption </legend>
HTML <legend> Tag Values
The value we set for an HTML <legend> element is a caption we want to set for a group of fields in a form data.
Example: using <legend> tag in HTML
See the Pen using <legend> tag in HTML by Omid Dehghan (@odehghan) on CodePen.