Element of
What does <legend> 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>.

Code Example

  <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">
Personal Information

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