HTML <fieldset> tag

The <fieldset> tag 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.

Standard attributes

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:</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:
Contact information: Name: Email:

Tips & notes

When using the <fieldset> tag with a form it should always come right after the <form> tag like in the above example.

Use the <legend> tag to set a title for the fieldset.

While the <fieldset> tag is usually used with forms, you don't necessarily have to use it with a form. A good example of using the <fieldset> 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> tag 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