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
Dartiniano Omran
2,045 PointsUse of label tag for forms
Hello,
I was learning about the label tag in forms and noticed that if my input element is preceded with text (or put after), then it seems to yield the same affect as the label tag. I understand using the label has the advantage of being able to point to the text and it adds focus to the field but other than that, why use it? It would be much quicker to simply add your text before or after the input element.
example:
<input type="text" name="username">Username:
versus
<label for="username">Username:</label>
<input type="text" name="username" id="username">
thanks!
2 Answers
Brandon Flade
2,769 PointsNot only does the label tag render UI benefits such as those that you previously mentioned. It also gives the label text semantic value. In other words, it allows code to identify a correctly formatted label and match it to the associated input. This is useful to things such as search engines and screen readers, which cannot always tell what a piece of text is without having markup to identify it. Hope that helped!
Dartiniano Omran
2,045 PointsAbsolutely it helped! Thanks for such a concise answer! I'm not normally one to take shortcuts anyway, but I thought I'd ask for better understanding.