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 trialChristopher Sea
3,726 PointsLabel Element OR Placeholder Attribute?
It seems as though both of these serve the same purpose. Should the use of one over the other depend on the purpose of the form/website, some other factor, or does it not matter at all?
1 Answer
Dave StSomeWhere
19,870 PointsThe serve two different purposes. The label is a separate element that provides text. The placeholder is an attribute that puts text inside the element like an input text element. Check out this example pen hopefully it will clear things up. Also, please note that the example links the label to the input element with the for attribute on the label matching the id attribute of the input, but a label can stand alone.
Luke Pettway
16,593 PointsLuke Pettway
16,593 PointsTo further elaborate, you should always use a label, it is a very important accessibility feature, and without them it can be a nightmare for screen reader users to use your forms. It provides context for what the form element is, so when a user that uses a screen readers tabs to that element, it can announce that it is a "first name" input.