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

In my personal a11y rules, placeholders should only ever contain the default values of optional fields. That's the only place they make perfect sense. Otherwise, just use a label. There is one exception, though: an <input type="search" placeholder="Search&hellip;">, which is already rather accessible on its own (though it may profit from a separate button).

Collapse
 
grahamthedev profile image
GrahamTheDev

Yeah search is one of those weird exceptions to a visible label, but even then aria-label="search the site" is advised.

Actually a better way is to do it "properly" and do:

<form role="search">
   <!-- your input, submit button (preferable, depending on implementation though) and a visually hidden label using CSS to make it accessible to screen readers but invisible visually -->
</form>
Enter fullscreen mode Exit fullscreen mode

Or use the floating label technique (where the label moves up when the field is focused) if space / design allows.