Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
Joe Williams4,014 Points
Unsure of what the HTML label is doing if I'm already using an Input ID
Regardless, in the example below, I'm not sure completely what's happening:
<p> <label for="new-task">Add Item</label><input id="new-task" type="text"><button>Add</button> </p>
If the input ID "new-task" is already identifying the text field, why am I labeling the Add Item title, which is just a title? What do they have to do with each other?
Brandon Barrette20,485 Points
So with labels, you use the ID of the element it's labeling in the for attribute. In this case, since your input has an id of "new-task", then the label is "for" that ID, "new-task".
With other input elements like checkboxes and radio buttons, doing this allows the label to be clickable as if it were the input, allowing you to use CSS to "hide" the checkbox/radio button and style the label instead.