HTML Tag Reference - HTML tag <legend>








This <legend> element inserts a descriptive caption in the container box of a <fieldset> element. You use this element to define the group of fields contained in the <fieldset> element.

Browser compatibility

<legend> Yes Yes Yes Yes Yes

What's new in HTML5

The "align" attribute is not supported in HTML5.

Attribute

Attribute Value Description
align top
bottom
left
right
Not supported in HTML5.
Set the caption alignment




Global Attributes

The <legend> tag supports the Global Attributes in HTML.

Event Attributes

The <legend> tag supports the Event Attributes in HTML.

Default CSS Settings

legend {
    display: block;
    padding-left: 2px;
    padding-right: 2px;
    border: none;
}




Example

A demo showing how to use <legend> tag.

<html>
<body>
     <form name="form1" method="post" action="">
          <p>
          <fieldset align="center">
               <legend>Credit Card Information:</legend>
               <input type="text" 
                      name="textfield" 
                      value="Name" 
                      size="60"/><br/>
               <input type="text" 
                      name="textfield2" 
                      value="Exp. date" 
                      size="50"/><br/>
               <input type="text" 
                      name="textfield3" 
                      value="Type" 
                      size="65"/><br/>
               <input type="text" 
                      name="textfield4" 
                      value="Number" 
                      size="45"/>
          </fieldset>
          </p>
     </form>
</body><!--   w  w  w  . j  av a2s. c  om-->
</html>

Click to view the demo