HTML5 Placeholder Polyfill Examples

The Placeholder Attribute has decent support across current Browsers. This Script adds support for the older generations including:

for more details on native support see the Browser suppport table at caniuse.com

Other than most other solutions this Polyfill will read the Placeholder Text to Screenreaders. It does this by adding the Text to the form fields asociated Label.

Update Placeholder Attribute

Form Elements with explicit labels (using id and for)






Form Element with visually hidden label (i.e. for search boxes)

Using the "visuallyhidden" class from i.e. HTML5 Boilerplate

HTML5 Boilerplate uses a way to visually hide elements that makes it impossible for containing elements (like the polyfilled Placeholder) to be visible. To make it work anyway the Polyfill changes said technique (only for labels) with a technique that is less obstrusive but still hides them.

Using the oldschool "offscreen" class (pushing the element to the far left using position:absolute)

Form Elements with implicit labels (wrapping the form element into the label)






Fork me on GitHub