DEV Community

Discussion on: I was shocked 😱 that placeholder text on an <input> (instead of a <label>) might TECHNICALLY PASS WCAG⁉ Do you agree?

Collapse
 
lexlohr profile image
Alex Lohr

If you enter a field with a default value in it, your input could be appended, which might be unexpected behavior and even more confusing than a placeholder that vanishes if you enter something else.

Thread Thread
 
grahamthedev profile image
GrahamTheDev • Edited

I think @codingsafari meant you should use a real world example of valid input as your placeholder text.

I would say you are both right depending on the circumstances.

So for a search box "Search...." might be applicable (a generic instruction) whereas for a "first name" field it might be better to have "e.g. Mike, Sarah etc." as the placeholder (providing an example of valid input).

For a normal input field, the following is "the ideal" Markup

<label for="dob">Your Date of Birth</label>
<p id="dob-instructions">Please enter your Date of birth in the format DD/MM/YYYY</p>
<input id="dob" type="text" aria-describedby="dob-instructions" placeholder="e.g. 17/01/1994">
Enter fullscreen mode Exit fullscreen mode

As the instructions are visible and clear in the <p>, which is correctly read after the label for screen readers using aria-describedby and we have linked the label to the input correctly (so you can click it to focus the input and screen readers get the info) the placeholder is ideal for an example of valid input.

Also as I said in the article, using old school for attributes on the label is more robust due to issues with voice control software and implicit (wrapped) labels!