Polyfills allow web developers to use an API regardless of whether it is supported by a browser or not, and usually with minimal overhead. Typically they first check if a browser supports an API, and use it if available, otherwise using their own implementation. Polyfills themselves use other, more supported features, and thus different polyfills may be needed for different browsers. The term is also used as a verb: polyfilling is providing a polyfill for a feature.
shim.gif, and similar terms such as progressive enhancement and graceful degradation were not appropriate, so he invented a new term. The term is based on the spackling paste brand Polyfilla, a paste used to cover up cracks and holes in walls, and the meaning "fill in holes (in functionality) in many (poly-) ways". The word since gained popularity, particularly due to its use by Paul Irish and in Modernizr documentation.
The distinction that Sharp makes is:
What makes a polyfill different from the techniques we have already, like a shim, is this: if you removed the polyfill script, your code would continue to work, without any changes required in spite of the polyfill being removed.
This distinction is not drawn by other authors. At times various other distinctions are drawn between shims, polyfills, and fallbacks, but there are no generally accepted distinctions: most consider polyfills a form of shim. The term polyfiller is also occasionally found.
- HTML5 Shiv
- In IE versions prior to 9, unknown HTML elements like
<nav>would be parsed as empty elements, breaking the page's nesting structure and making those elements impossible to style using CSS. One of the most widely used polyfills, html5shiv, exploits another quirk of IE to work around this bug: calling
document.createElement("tagname")for each of the new HTML5 elements, which causes IE to parse them correctly. It also includes basic default styling for those HTML5 elements.
- Though most polyfills target out-of-date browsers, some exist to simply push modern browsers forward a little bit more. Lea Verou's -prefix-free polyfill is such a polyfill, allowing current browsers to recognise the unprefixed versions of several CSS3 properties instead of requiring the developer to write out all the vendor prefixes. It reads the page's stylesheets and replaces any unprefixed properties with their prefixed counterparts recognised by the current browser.
- Possibly one of the most anticipated features of CSS3, Flexible Box Layout (a.k.a. Flexbox) promises to be an extremely powerful tool for laying out interface elements. WebKit and Mozilla engines have supported a preliminary draft syntax for years. Flexie implements support for that same syntax in IE and Opera. However, the draft spec has undergone a drastic revision to a new (and much more powerful) syntax, which is not yet supported by Flexie. Flexie can still be used along with the old syntax, but the developer must make sure they include the new syntax for future browsers as well.
- CSS3 PIE
- PIE ("Progressive Internet Explorer") implements some of the most popular missing CSS3 box decoration properties in IE, including border-radius and box-shadow for IE 8 and below, and linear-gradient backgrounds for IE 9 and below. Invoked as a HTC behavior (a proprietary IE feature), it looks for the unsupported CSS3 properties on specific elements and renders those properties using VML for IE 6–8 and SVG for IE 9. Its rendering is mostly indistinguishable from native browser implementations and it handles dynamic DOM modification well.
- JSON 2
- Douglas Crockford originally wrote json2.js as an API for reading and writing his (then up-and-coming) JSON data format. It became so widely used that browser vendors decided to implement its API natively and turn it into a de facto standard; json2.js was transformed from a library to a polyfill after the fact.[clarification needed]
- FlashCanvas is an implementation of the HTML5 Canvas API using an Adobe Flash plug-in. A rare commercial polyfill, it comes in a paid version, as well as a free version, which lacks a few advanced features like shadows.
- John Dyer's MediaElement.js polyfills support for
<audio>elements, including the HTML5 MediaElement API, in older browsers using Flash or Silverlight plug-ins. It also provides an optional media player UI for those elements, which is consistent across all browsers.
-  Authentication protocol proposed by Mozilla, failed to gain traction.
- Webshims Lib
- Alexander Farkas's Webshims Lib aggregates many other polyfills together into a single package and conditionally loads only those needed by the visiting browser.
- The use of the term shiv here is a pun or mistake on shim.
- "It typically checks if a browser supports an API. If it doesn’t, the polyfill installs its own implementation. That allows you to use the API in either case."
- Bruce Lawson; Remy Sharp. "Introducing Polyfills". Introducing HTML5. pp. 276–277.
- Sharp, Remy. "What is a polyfill?". Retrieved 13 January 2012.
- Ian Hickson (2008-01-23). "Mistakes, Sadness, Regret".
“This piece of information makes building an HTML5 compatibility shim for IE7 far easier than had previously been assumed.”
- "HTML5 Cross browser Polyfills". Archived from the original on 2010-09-28.
- "What is the difference between a shim and a polyfill?".
- Chuck Hudson; Tom Leadbetter (2011). HTML5 Developer's Cookbook. p. 121.
- "navigator.id". Mozilla Developer Network. 30 June 2012.
- "List of polyfills providing HTML5 facilities". GitHub: Modernizr project.
- Manian, Divya; Irish, Paul; Branyen, Tim; Montgomery, Connor; Verschaeve, Arthur; et al. (eds.). "HTML5 Polyfill List by Feature". HTML5 Please.
The recommendations... represent the collective knowledge of developers who have been deep in the HTML5 trenches