[thelist] <fieldset> and <legend> vs <h2>

Robert O'Rourke rob at sanchothefat.com
Wed Jun 27 09:07:15 CDT 2007


Bill Moseley wrote:
> I tend to use fieldsets with every form, even for forms that have a few
> elements.
>   

In XHTML strict it's a requirement so I stick to as a coding standard.

> Is it appropriate to use if the form only has a single field?
>
>
>     <form>
>         <fieldset>
>             <legend>Name</legend>
>             <input type="text" name="name" />
>         </fieldset>
>         <div><input type="submit" /></div>
>     </form>
>
> It's been recommended that this is overkill and should use <h2> for
> the legend instead (and I assume wrap the fields in some block-level
> tag).
>   

In terms legends and the like I don't use them for main headings on 
forms because they're read out before every label/field. Sometimes on 
bigger forms you have to take two lots of similar information like a 
billing address and delivery address so I put a fieldset around each set 
of similar labels and inputs with a legend containing 'delivery address' 
or 'billing address' for example:

<fieldset>
	<legend>Delivery Address</legend>
	<label for="street">Street: <input id="street" ... /></label>
	<label for="loc">Locality: <input id="loc" ... /></label>
	<label for="reg">Region: <input id="reg" ... /></label>
 	...etc...
</fieldset>

<fieldset>
	<legend>Billing Address</legend>
	<label for="b-street">Street: <input id="b-street" ... /></label>
	<label for="b-loc">Locality: <input id="b-loc" ... /></label>
	<label for="b-reg">Region: <input id="b-reg" ... /></label>
 	...etc...
</fieldset>

So the labels are the same in each fieldset but they are clearly marked 
as a different set of information.

It seems like thats the consensus from the other replies too.

Rob



More information about the thelist mailing list