Producing web pages
* HTML CSS DHTML XHTML A to Z of tags        Accessibility          Design

Grouping fields on a form

Fields on a form can often belong to a group, for example, the different parts that make up an address. You might want to make it clear which fields belong together by putting them in a box or adding shading but in HTML this difficult (although you could use a table).

HTML 4.0 has a new <fieldset> tag that allows you to group fields together. For example:

<fieldset>
Name:    <input type="text">
Address: <input type="text">
Email:   <input type="text">
</fieldset>

The browser should find a way of telling the user that the fields are a group. Internet Explorer 5 puts a box round the fields.

You can also use the <legend> tag in a fieldset to provide a title for the group, it is a bit like the <caption> tag in a table. You can only have plain text in a <legend> tag. Take care though, if the browser can't handle legends, it just displays the tag as text and makes a pig's ear of your well-crafted form.