<legend> HTML Tag
Disclosure: Your support helps keep the site running! We earn a referral fee for some of the services we recommend on this page. Learn more
- Element of
- HTML Web Forms Tutorial For Coding Beginners
- What does
<legend> HTML Tag
do? - The <legend> element is used to add a caption to a group of related form <input> elements that have been grouped together into a <fieldset>.
- Display
- block
- Usage
- textual
Code Example
<form>
<fieldset>
<legend>Personal Information</legend>
<label for="name">Name</label><br>
<input name="name" id="name"><br>
<label for="dob">Date of Birth<label><br>
<input name="dob" id="dob" type="date">
</fieldset>
</form>
Titles for Form Sections
The <legend>
element provides titles for form sections, providing a nice alternative to the <h*>
headline elements. They are designed to be used with the <fieldset>
element, and (strictly speaking) should only be used inside of one. Organizing form fields into <fieldset>
groups, with appropriate <legend>
captions can help make complicated forms more attractive and easier to use. For other tips on working with forms see our form design and form usability tutorials.
Browser Support for legend
All | All | All | All | All | All |