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 trialMeredith Wiegman
4,804 PointsForm field focus by placing input element inside label element
Nick describes how to label a form field and have the browser automatically focus the field when clicking on the label, like this:
<label for="name">Name:</label>
<input type="text" id="name" name="user_name">
However, it seems that you can also acheive this by nesting the input inside the label tag like so:
<label>Name:<input type="text" id="name" name="user_name"></label>
Are there any pros/cons to labeling forms in this way?
1 Answer
Rich Bagley
25,869 PointsHi Meredith,
I tend to leave the input unwrapped but I guess it's down to personal preference as both methods have pros and cons.
This question on Stack Overflow covers the same thing so may help :)
-Rich