HTML <legend> Tag

The <legend> tag defines a caption for a <fieldset> element which is its parent.

This caption is shown by default in the top-left corner of the fieldset's frame but this visual aspect can be changed using style sheets.

Syntax

The <legend> tag comes in pairs. The content must be written between opening (<legend>) and closing ( </legend>) tags.

Example

<!DOCTYPE html>
<html>
   <body>
      <form>
         <fieldset>
            <legend>Personal Informations:</legend>
            Name: <input type="text"><br/>
            Email: <input type="text"><br/>
            Date of birth: <input type="text"><br/>
            Place of birth: <input type="text">
         </fieldset>
      </form>
   </body>
</html>

Result


Attributes

Attribute Value Description
align top
bottom
left
right
Defines the alignment of the caption.
It is not used anymore in HTML5.

The <legend> tag also uses the Global Attributes.