Browser Compatibility & Polyfills
Why browsers disagree on feature support, how to check and plan for it, and how polyfills and transpilation bridge the gap.
Browser Compatibility & Polyfills
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- Browsers differ because each vendor ships features on its own schedule, so new CSS and JavaScript capabilities land unevenly across Chrome, Safari, and Firefox.
- Checking caniuse.com before relying on a feature is cheaper than discovering the gap from a user's bug report.
- Progressive enhancement builds up from a working baseline, while graceful degradation builds down from a full-featured experience — they solve the same problem from opposite directions.
- A polyfill adds a missing runtime API; a transpiler like Babel rewrites newer syntax into older syntax that already runs everywhere.
- Feature detection checks whether the browser actually supports something at runtime, which is more reliable than guessing from the browser's name.
Why “the browser” is actually several browsers
It’s tempting to think of “the web” as one platform that your code either works on or doesn’t. In reality, a browser is a specific piece of software — an engine for parsing HTML, applying CSS, and running JavaScript — built and shipped by a specific vendor on its own release schedule. Chrome uses Blink, Safari uses WebKit, Firefox uses Gecko. Each team implements new standards at its own pace, decides which experimental proposals to ship early, and fixes its own bugs on its own timeline. The W3C and WHATWG can standardize a new CSS property or JavaScript method, but standardizing it doesn’t make it appear in every engine simultaneously — it just gives vendors a shared target to implement toward, each in their own time.
This is why a CSS feature can work flawlessly in Chrome the week it’s announced and not reach Safari for a year, or why a JavaScript method you use constantly might silently not exist on an older phone’s browser. It isn’t a bug in your code or a failure of the standard — it’s a structural fact about how the web platform evolves through several independent implementations rather than one central release.
Checking before you rely on something
The fix for “I didn’t know that wasn’t supported everywhere” is to check before you ship, not after a bug report arrives from a user on an unusual device. caniuse.com is the standard reference: search any CSS property or JavaScript API and it shows exactly which browsers and versions support it, often broken down further by partial support or known bugs in specific implementations. Making this check part of your normal workflow — before reaching for a shiny new feature, not after — turns compatibility from a surprise into a planned decision: ship it as-is, ship it behind a fallback, or wait.
Two ways to handle the gap
Once you know a feature isn’t universally supported, there are two complementary philosophies for handling that gap, and the names describe the direction you build in.
Progressive enhancement starts from a simple, functional baseline — plain HTML that works with no JavaScript and no advanced CSS at all — and then layers richer behavior on top, conditionally, for browsers that can handle it. A form that submits normally via HTML without any JavaScript, then gets enhanced with client-side validation and a smoother submit experience if JavaScript loads successfully, is progressive enhancement in practice. Nothing ever breaks completely; browsers that can’t run the enhancement simply don’t get it, and the core task still works.
Graceful degradation runs the same logic in the opposite direction. You build the full, modern experience first, and then explicitly handle what happens when a browser can’t support some part of it — showing a static image instead of an interactive canvas animation, for instance, when the canvas API isn’t available. The end state for the user can look similar either way; the difference is which version you treat as the default you design for first, and which one you treat as the exception you have to remember to handle.
Bridging the gap: polyfills and transpilation
When you do decide to use a newer feature despite inconsistent support, two distinct tools bridge the gap, and conflating them is a common mistake.
A polyfill is a piece of JavaScript that implements a missing runtime capability using code that does run in the old environment. If an older browser’s JavaScript engine never implemented Array.prototype.flat, a polyfill defines that method by hand — using array methods that were available — and attaches it to Array.prototype, so your code can call .flat() as if the browser had supported it natively all along. Polyfills patch missing behavior.
A transpiler, most commonly Babel, works on syntax instead. If you write modern JavaScript syntax — arrow functions, optional chaining, newer class syntax — a transpiler rewrites that code at build time into older syntax that produces the same behavior but runs on engines that never implemented the new grammar. Babel can’t invent a missing API the way a polyfill can; it can only translate syntax the parser doesn’t understand into syntax it does. In practice, real projects need both: Babel to compile newer syntax down, and a polyfill library (historically core-js, often bundled through @babel/preset-env’s useBuiltIns option) to patch in missing runtime APIs for whatever browsers the project still targets.
Detecting features instead of guessing from the browser’s name
Early web development leaned on “browser sniffing” — reading the navigator.userAgent string and branching logic based on which browser it claimed to be. This is fragile: UA strings get spoofed, browsers change their reported identity over major versions, and a new browser the sniffing code has never heard of gets treated as unsupported even if it actually implements everything needed.
Feature detection is the reliable alternative: ask the browser directly whether it supports the thing you want to use, at runtime, rather than inferring support from its name. Checking if ('IntersectionObserver' in window) before using that API, or using @supports in CSS to apply a rule only when the browser understands a given property, tests the actual capability instead of a proxy for it. This keeps working correctly as browsers update, rather than requiring you to maintain a brittle list of which named browser versions support what.
Check yourself
Why do browsers end up supporting different sets of features at any given time?
Each browser vendor implements and ships new web platform features on its own independent schedule and through its own engine, so a feature can land in Chrome months or years before it reaches Safari or Firefox, or never reach one of them at all.
What's the practical difference between progressive enhancement and graceful degradation?
Progressive enhancement starts from a simple baseline that works everywhere and layers richer behavior on top for browsers that support it, while graceful degradation starts from the full-featured experience and explicitly plans a fallback for browsers that can't run it — same goal, opposite starting point.
What problem does a polyfill solve that a transpiler like Babel does not?
A polyfill supplies a missing runtime API or object that a browser's JavaScript engine never implemented at all, such as `Array.prototype.flat`, while a transpiler only rewrites newer syntax into equivalent older syntax and cannot invent an API that doesn't exist in the runtime.
Why is feature detection more reliable than checking the user agent string?
Feature detection asks the browser directly whether it supports a given API or property, which stays accurate as browsers update, whereas user-agent sniffing hardcodes assumptions about specific browser versions that break the moment a browser updates, spoofs its UA string, or a detail changes that the sniffing code didn't anticipate.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.