HTML legend Tag defines the caption or title for the fieldset tag. The legend tag must be first child of it's parent element.
Table of Contents
Syntax of HTML legend Tag
The Syntax of HTML legend Tag is shown below, It has both starting tag and ending tag.
<legend>Biodata Form</legend>
Usage of HTML legend Tag
HTML legend Tag is used to define the title or caption for it's parent element. Most commonly it is used inside the fieldset tag to define it's caption.
HTML legend Tag is the first tag inside the fieldset tag.
HTML legend Tag is a block level element.
Example of HTML legend Tag
Simple example of HTML legend Tag is shown below.
<form action="/action.php">
<fieldset>
<legend>Student Form</legend>
<label for="name">Name:</label>
<input type="text" id="name" name="uname"><br>
<label for="email">Email:</label>
<input type="email" id="email" name="uemail"><br>
<label for="number">Contact:</label>
<input type="number" id="number" name="unumber"><br><br>
<input type="submit" value="Submit">
</fieldset>
</form>
Output
In above example we have a simple student information form. The legend tag is used in this form inside the fieldset tag to define the title or caption, which also explains the purpose of the form.
Browser Support for HTML legend Tag
HTML legend Tag is supported by all major browsers including Safari and Internet Explorer.
Global Attributes Support in HTML legend Tag
The HTML legend Tag supports all Global Attributes.
Event Attributes Support in HTML legend Tag
The HTML legend Tag supports all Event Attributes.
HTML legend Tag Video
Watch our video on HTML legend Tag.