Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using placeholder instead of label

When it comes to accessibility, it's a common practice to not use placeholders as substitute for labels because upon entering something into the field, the placeholder disappears. But what if my placeholder acts as a visual label afterwards?

Before focus and entry

After focus and entry

Is it still okay to only use a placeholder in this case in place of an actual Label? If so, do I also need to tag it with an aria-label as well?

like image 514
Poov Fwv Novlwv Lis Avatar asked Oct 16 '25 04:10

Poov Fwv Novlwv Lis


1 Answers

I would not recommend using a placeholder attribute or other container in place of a <label> element.

This is not an issue of having a "visual label", as you described. The <label> element is associated with the <input> element programmatically at the data-level.

<label for="middle-initial">Middle Initial</label>
<input id="middle-initial">

The placeholder attribute is essentially invisible to screen readers, so it can be used in conjunction with <label>, however it should not be used as a substitute for a <label>.

If you really don't like the visual appearance of having the <label> on your page, you can position the text off screen using CSS, or if you're currently using bootstrap, you can use the .sr-only class.

like image 155
Josh Avatar answered Oct 17 '25 17:10

Josh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!