E-mail List Archives

Re: labels in forms


From: Christian Heilmann
Date: May 31, 2007 6:00PM

> Hi all,
> I'd like some clarity on labels in forms please. Is it OK to put <label
> for="fname"> if it for a first name input box or is it better to put <label
> for="firstname"> or even <label for="first name">. I wasn't sure if screen
> readers and the like actually read the value in the label and whether it is
> best to have something in there that actually makes sense to the visitor or
> if it is fine to use abbreviations.

The for attribute connects with the id of the element it should
connect to. This is only for the browser and will not be read out. As
IDs cannot have spaces "first name" would be wrong. You can call the
ID whatever you please though, with form fields the name attribute is
what is sent to the server. IDs are only in HTML as hooks for CSS and
DOM, and don't have anything to do with the backend or with assistive

<label for="fn">First Name</label><input type="text" name="firstname"
id="fn"> is as valid as <label for="scoobydoo">First
Name</label><input type="text" name="firstname" id="scoobydoo">

Chris Heilmann
Book: http://www.beginningjavascript.com
Blog: http://www.wait-till-i.com
Writing: http://icant.co.uk/