HTML <legend> tag

The <legend> tag is used to set a title for a fieldset. A fieldset is used to group together a set of elements that you choose by drawing a box around them. This will present those elements in a more easily readable way by adding emphasis.

Attributes

Attribute Possible values Description
align left, right, top, bottom Deprecated. Sets the alignment of the fieldsets title

Standard attributes

accesskey, class, dir, id, lang, style, title, xml:lang

For more information on standard attributes, check out our HTML standard attributes reference page.

Event attributes

onclick, ondblclick, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, onkeydown, onkeypress, onkeyup

For more information on event attributes, check out our HTML event attributes reference page.

Example

<b>Without a fieldset:</b> <form> Name: <input type="text" name="name" /> E-mail: <input type="text" name="email" /> </form> <b>With a fieldset (without legend):</b> <form> <fieldset> Name: <input type="text" name="name" /> Email: <input type="text" name="email" /> </fieldset> </form> <b>With a fieldset (with legend):</b> <form> <fieldset> <!-- the <legend> tag sets a title for the fieldset --> <legend>Contact information:</legend> Name: <input type="text" name="name" /> Email: <input type="text" name="email" /> </fieldset> </form>
Output:
Without a fieldset:
Name: Email:
With a fieldset (without legend):
Name: Email:
With a fieldset (with legend):
Contact information: Name: Email:

Tips & notes

Use the <fieldset> tag together with the <legend> tag.

While the <fieldset> + <legend> tags combination is usually used with forms, you don't necessarily have to use it with a form. A good example of using the <fieldset> tag with something else besides a form can be found on our Web development jobs tutorial. Scroll down a little on this page until you see the green box. This is the <fieldset> + <legend> tags at work without a form.

Web Reference
  1. CSS reference
  2. RSS reference
  3. HTML reference


© Copyright 2011-2012 Landofcode.com
Terms of use | Privacy policy | Copyright information | Make a donation