Feature detection
Feature detection is the practice of testing whether a runtime environment supports a particular capability.
Vanilla Web
Feature detection is a technique for determining at runtime whether a browser or environment supports a particular capability.
- How it is used
- Keeps a web app usable across differing browser capabilities while enabling optional features where available.
- How deep it goes
- Demonstrates property-presence checks for the Permissions API and file pickers, including picker constraints, without exploring browser internals.
- Examples
- Uses a guarded geolocation permission query and guarded file-opening and file-saving workflows.
- What you can do after
- Apply it via native JavaScript property checks to use supported APIs conditionally and provide a fallback.
HTML5 in Action
Feature detection is the technique of checking whether a software environment supports a particular capability.
- How it is used
- Selects browser-specific resources and fallbacks when HTML5 feature support varies.
- How deep it goes
- Explains feature tests and conditional loading, then applies checks to form validation, database objects, and Canvas contexts.
- Examples
- Uses a month-picker fallback, a localStorage polyfill, vendor-prefixed database objects, and a Canvas 2D context check.
- What you can do after
- Apply it via Modernizr to test support and conditionally load a fallback.
Secrets of the JavaScript Ninja, Second Edition
Checking whether a runtime environment supports a capability by testing for the feature itself.
- How it is used
- Uses runtime capability checks to select supported APIs or fallbacks in reusable cross-browser JavaScript.
- How deep it goes
- Defines presence checks and works through API selection and a polyfill, while noting that existence may not guarantee implied functionality.
- Examples
- Uses event-handler API selection and an Array.prototype.find fallback as concrete examples.
- What you can do after
- Apply capability checks to choose between standard and legacy event APIs or provide an Array.find fallback.
Read how Secrets of the JavaScript Ninja, Second Edition explains feature detection →
What to know first
- canvas elementThe HTML canvas element is a scriptable bitmap drawing surface in a web document, with an API for rendering graphics.
- web standardsWeb standards are publicly specified technical rules and interfaces that define web technologies and promote interoperable behavior across the web.
Related concepts
- addEventListeneruses · addEventListener is a method that registers a callback to be invoked when a specified event is dispatched to an event target.
- fallbackuses · A fallback is an alternative behavior, result, resource, or processing path selected when a preferred option fails, is unavailable, or is inadequate.
- getContext()uses · getContext() is a canvas element method that returns a rendering context for a specified graphics mode.
- micro-libraryused by · A micro-library is a small software library that provides narrowly scoped functionality and can be composed with other libraries.
- Modernizrused by · Modernizr is a JavaScript library that detects support for web platform features in a browser.
Questions about feature detection
What is feature detection?
Feature detection is the practice of testing whether a runtime environment supports a particular capability.
Which Manning books explain feature detection?
Vanilla Web, HTML5 in Action and Secrets of the JavaScript Ninja, Second Edition.
What should I know before learning feature detection?
Manning books that teach feature detection usually introduce canvas element and web standards first.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.


