Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Build cross-browser behavior by detecting the capability your app needs, using the enhanced path when it exists, and keeping a usable fallback when it does not. Modernizr reports feature support through JavaScript properties and, by default, CSS classes; it detects capabilities but does not add unsupported ones. Start from the app’s real requirements, then build and test both paths.

What Modernizr does—and what it does not

Modernizr tests browser capabilities rather than identifying a browser by name or user-agent string. That distinction matters because browsers and versions can differ in support, and support can change. A positive result tells your app that a tested capability is available; it does not supply a missing capability or guarantee that the complete user experience works as intended.

By default, results are available as properties on the Modernizr object and as feature-state classes on the root HTML element. For example, a CSS gradients test can add cssgradients when supported or no-cssgradients when unsupported. Modernizr supports custom builds so you can include the detects your app needs rather than every available test.

Plan the enhanced path and fallback

  1. List the capabilities the design actually uses. Name specific needs, such as CSS gradients or a particular JavaScript behavior. Avoid broad browser-version blacklists.
  2. Choose the matching detect. Check the current Modernizr documentation for the exact detect and what it tests. Individual tests can differ in meaning and reliability; do not assume a detect for a loosely related property proves the behavior your app requires.
  3. Define a baseline that works without the enhancement. Keep content, navigation, and essential actions available. Add the feature as an improvement, not as the only route to a core task.
  4. Decide how to handle unsupported browsers. Use the baseline, or separately evaluate a suitable polyfill if the feature is essential. Modernizr itself is not a polyfill.
  5. Test both feature states in the actual app. Check the enhanced and fallback experience on the browsers and devices relevant to your audience.

Get Modernizr through the project’s npm workflow

The Modernizr project README says its website is outdated and broken and directs developers to build from npm instead. Follow the current npm and build instructions in the project repository rather than relying on the old website’s workflow. The available project guidance describes npm-based programmatic builds and a command-line build, with configuration for selecting feature detects. Confirm package details and commands against the current repository before copying them into a project; the available guidance does not establish the latest package release.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A custom build should contain the detects the app uses. This keeps the generated Modernizr artifact focused on the requirements you identified. The project README also describes an all-features configuration as a reference, but a full build is not a substitute for choosing and verifying the tests your app needs.

Apply feature detection in CSS

For presentation changes, use the classes Modernizr adds to the root element by default. A gradient can enhance a plain background while preserving a solid-color fallback:

body {
  background-color: #f2f2f2;
}

.cssgradients body {
  background-image: linear-gradient(#fff, #e8e8e8);
}

With the default class behavior, supported browsers receive the cssgradients class and use the gradient rule; browsers without support retain the solid background. Keep the fallback readable and useful. Modernizr also documents a classPrefix option and configuration that disables classes, so verify the generated class names and settings if your project customizes them.

Choose behavior in JavaScript

For behavior changes, inspect the property corresponding to the detect in your custom build. The following pattern keeps a baseline action available and adds an enhancement only when the capability is present:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
if (Modernizr.cssgradients) {
  // Apply behavior that requires the tested capability.
} else {
  // Keep the baseline behavior available.
}

Replace the illustrative branch with a real capability your app needs and its corresponding detect. Do not treat a passing check as proof that unrelated behavior works; test the actual interaction and keep errors or unsupported states from blocking essential tasks.

Write a custom test only when needed

Modernizr’s addTest helper accepts a feature name and a boolean-producing expression or function. The feature name is lowercased on the Modernizr object. A custom test should check the behavior the application depends on—not merely the presence of a global or property that may not demonstrate that behavior. Verify the test against target browsers before basing a core path on it.

Handle asynchronous tests deliberately

Do not treat an asynchronous result as though it were available synchronously. The project documents Modernizr.on(feature, callback) for asynchronous tests; the callback is called once for each registration. For a custom asynchronous test that needs explicit control over its result, the project guidance recommends addTest. Use a synchronous branch for synchronous detects and wait for asynchronous results before using them.

Test the fallback and enhanced experience

Modernizr’s detection result is not a substitute for testing the app. Exercise real tasks in both states, including layout, input, navigation, and recovery from a failed enhancement. The project README describes unit and integration test workflows, including npm test and browser-served test pages; consult the current repository instructions for how to run them and open the relevant pages in the browser you want to check.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Verify the detect you selected in the target browsers and confirm it measures the behavior your code needs.
  • Check that users can still read content and complete essential actions when the detect is false.
  • Check that the enhancement does not break the baseline when it loads or executes.
  • Test relevant devices and browser scenarios, not just one browser family or a desktop viewport.
  • If considering a polyfill, separately verify that it supplies the required behavior and is suitable for your target browsers.

Common problems and fixes

The Modernizr class or property is missing

Check that the build includes the detect, that the generated artifact is loaded by the page, and that configuration has not changed the class behavior or prefix. A custom build that omits a test cannot report its result.

The fallback never appears

Inspect the root element’s actual feature-state class and the generated CSS selectors. If classes are disabled or prefixed, update the CSS or configuration consistently. Also confirm that the relevant detect is included.

The positive result does not guarantee the app works

A feature detect reports the tested capability, not the correctness of every dependent interaction. Confirm that the chosen test matches the exact behavior in use, then test the app path itself.

A custom asynchronous check runs too early

Wait for the asynchronous result with the documented callback pattern, or use the project’s custom-test guidance when you need control of an asynchronous test. Do not read an unresolved result as a final supported/unsupported decision.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Old setup instructions do not match your project

Use the project’s current npm and build instructions. The README warns that the project website is outdated and broken; its version notes are not proof of the package’s latest release or of current bundler integrations.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If what you need is a website screenshot rather than a Modernizr-based browser feature test, ScreenshotNeo is a website screenshot API and MCP server. A single GET request can return an image or PDF. For example, with cURL:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for request options and response details. Cookie banners, popups, and chat widgets are removed before the shot; bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots. The Free plan includes 1,000 screenshots a month with no card, and paid plans start at $5 for 3,000. Sign up for free.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.