The above example will display a form with a fieldset and a legend set as "Login Information".
Explanation
The <legend>
tag is used to provide a caption for the <fieldset>
element. It is used to group form elements together, and it indicates to the user what the group is for. The <legend>
element must be the first child element of the <fieldset>
element.
Use
- The
<legend>
tag is mainly used to provide a caption for the <fieldset>
element.
- It is used to group related elements inside a form.
Important Points
- A
<fieldset>
tag can have only one <legend>
tag.
- The
<legend>
tag must be the first child element of the <fieldset>
tag.
- The
<legend>
tag should not be used outside the <fieldset>
tag.
Summary
The <legend>
tag is used in conjunction with the <fieldset>
tag to provide a caption for a group of related form elements. It is useful for creating well-structured forms with clearly labeled sections.