Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML HTML Forms Organizing Forms The Label Element

Do we really need to have the "for" attribute in a label ?

It only directs the user to the input. I think that the user can click on the input himself. Often, the input boxes are bigger and easier to click than a tiny label. So, I am unable to see how the for attribute can be useful.

2 Answers

I believe the for attribute also helps assistive technologies identify the correct label for each field for people with disabilities. So yes, I would say that it's probably best to always use the for attribute.

You can use labels without "for" attribute, but still have this "click on the label" feature. Just use another syntax:

         <p>Just another syntax for labels: wrap our input</p>
         <form action="#" method="post">
           <label>Name:
             <input type="text" id="name" name="user_name">
           </label>
         </form>