Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Placeholders vs labels #15610

Closed
danielnixon opened this issue Jan 19, 2015 · 6 comments
Closed

Placeholders vs labels #15610

danielnixon opened this issue Jan 19, 2015 · 6 comments

Comments

@danielnixon
Copy link
Contributor

Re #15327, I don't think HTML5 placeholders are enough.

Should

<span class="input-group-addon" id="basic-addon1">@</span>
<input type="text" class="form-control" placeholder="Username" aria-describedby="basic-addon1">

be more like

<span class="input-group-addon" id="basic-addon1">@</span>
<input type="text" class="form-control" placeholder="you@example.com" aria-label="Username" aria-describedby="basic-addon1">

or even

<label for="username" class="sr-only">Username</label>
<span class="input-group-addon" id="basic-addon1">@</span>
<input type="text" id="username" class="form-control" placeholder="you@example.com" aria-describedby="basic-addon1">

? See e.g. MDN or The HTML5 placeholder attribute is not a substitute for the label element or Placeholders are not Substitutes for Labels.

@mdo
Copy link
Member

mdo commented Jan 19, 2015

/cc @patrickhlauke

@cvrebert
Copy link
Collaborator

But the user cannot change the cents field, it's always zero cents, so that nitpick doesn't seem right.

@danielnixon
Copy link
Contributor Author

D'oh, you're right.

@patrickhlauke
Copy link
Member

In the first example, the input is not an email address, but a twitter user name. the field is prefixed with the visible "@". placeholder="Username" is correct in this context.
As the placeholder attribute is exposed to assistive technologies (in case other methods, like a proper <label>, an aria-label, aria-labelledby or title are not present) as an accessible name, it functions in exactly the same way in this case as the proposed additional aria-label.
The major objections to using placeholder as a form of labelling are usability-related. In an ideal world devs would always provide a visible <label>, but when they decide not to, the above pattern is appropriate (and works well for assistive technologies too).

@patrickhlauke
Copy link
Member

Related though, perhaps it's worth adding an example that shows the use of an <input> with an .input-group-addon, but also a proper <label> ... will slot that on my to-do list

@mdo
Copy link
Member

mdo commented Jun 18, 2015

Going to punt on this, though if you wanted to do a label variation for the docs @patrickhlauke, I'm not against it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants