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

What's the difference between for="abc" and <input> inside a <label> element?

Hello, why i can't simply add input element inside the label element? <label>Name: <input type="text"></label> Is it because i can put the <label for="name"> element above the <input> element? Or is it just "bad html" ? <label>Name<input></label> will display "inline" and <label></label><input> can be displayed as block element or am i wrong?

I know the html basics i just wanted to improve or "fix" my html knowledge to improve myself.

1 Answer

Steven Parker
Steven Parker
231,275 Points

According to the MDN reference page, input elements are allowed inside labels. What made you think they were not?

But by using "for" property, you can achieve desired behavior without nesting, which makes the code a bit easier to read and maintain.