October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk6 min

How to Build Cross-Browser Web Apps with Modernizr

Use Modernizr to detect the capabilities your app needs, enhance supported browsers, and keep essential tasks working through tested fallbacks.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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

Build cross-browser experiences by detecting the specific browser capabilities your app needs, using enhanced behavior when those capabilities are available, and preserving a usable fallback when they are not. Modernizr reports feature support through JavaScript properties and, by default, classes on the root HTML element; it detects capabilities but does not add missing ones.

What Modernizr does—and what it does not

Modernizr is a feature-detection library. Instead of inferring capabilities from a browser name or user-agent string, your app can check for the particular feature it intends to use. That is more precise because support can differ between browsers and change over time.

As an Amazon Associate I earn from qualifying purchases.

Results are available as properties on the Modernizr object and, by default, as classes on the document root. A positive result tells you that a detect reports support; it does not provide a fallback or guarantee that every part of your app will behave as intended. Your code must supply the alternative experience.

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

Get Modernizr and build only the detects you need

The project README directs developers to install and build Modernizr from npm, and warns that its website is outdated and broken. Follow the repository’s current npm and CLI instructions rather than copying older integration examples. The project documents custom builds that select feature detects, with its all-features configuration available as a reference. A focused build avoids including tests your app does not use.

Because the project’s README does not establish the latest package release, check the current package instructions before pinning a version or relying on an older command. Its v4 notes say Node.js 10 and below are no longer supported; that note is not evidence that v4 is the latest release.

Build the app around a working baseline

  1. Inventory the capabilities your design actually uses. List the specific browser features behind optional styling or behavior. Avoid broad browser-version blacklists.
  2. Select matching detects. Configure a custom npm/CLI build with the feature tests your app needs. Verify each selected detect and its current usage against the project documentation and the browsers you target.
  3. Make core tasks work without enhancements. Keep essential content, navigation, and actions available before adding optional effects. Decide what a user can still accomplish when a detect is false.
  4. Add enhancements conditionally. Use CSS classes for presentation and JavaScript properties for behavior. Keep the fallback readable, operable, and appropriate to the task.
  5. Exercise both states in the real app. Test the enhanced and fallback paths in the browsers and devices relevant to your audience. A reported feature state is not a substitute for testing the resulting experience.

Use feature classes for CSS

By default, Modernizr adds a class for a supported feature and a no--prefixed class when it is unsupported. For example, a CSS gradient enhancement can be paired with a solid-color fallback:

/* Baseline: remains visible without gradient support. */
.card {
  background-color: #263238;
  color: white;
}

/* Enhancement when Modernizr detects CSS gradients. */
.cssgradients .card {
  background-image: linear-gradient(135deg, #263238, #455a64);
}

/* Optional explicit unsupported state. */
.no-cssgradients .card {
  background-image: none;
}

The baseline rule is important: if Modernizr is absent, delayed, or configured not to add classes, the component still has a usable appearance. The explicit .no-cssgradients rule is useful when the unsupported state needs different styling; it is not required when the baseline already covers it.

Free tools Windows power users keep installed

One-click scans. No signup required.

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

The project documents a classPrefix configuration option and an option to disable classes. If you change either behavior, update your selectors and do not assume the default root classes are present.

Use JavaScript properties for behavior

Check the property corresponding to the feature before taking the enhanced path. This example uses a hypothetical feature called examplefeature; replace it with a real detect included in your build and verify that its semantics match the behavior you need.

const output = document.querySelector("#status");

if (Modernizr.examplefeature) {
  enableEnhancedExperience();
} else {
  enableFallbackExperience();
}

function enableEnhancedExperience() {
  output.textContent = "Enhanced experience is available.";
}

function enableFallbackExperience() {
  output.textContent = "Using the compatible version.";
}

Keep the fallback meaningful rather than treating a failed detect as a reason to hide an essential feature. A detect can only inform the branch; your application defines what each branch does.

Register a custom test when the built-in detects do not fit

Modernizr’s addTest helper accepts a feature name and a boolean-producing expression or function. Use a check for the actual behavior the app requires—not merely the presence of a loosely related global or property. Names are lowercased on the Modernizr object.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Modernizr.addTest("examplefeature", function () {
  return testTheBehaviorMyAppNeeds();
});

if (Modernizr.examplefeature) {
  enableEnhancedExperience();
} else {
  enableFallbackExperience();
}

testTheBehaviorMyAppNeeds is an application-specific function, not a Modernizr API. Implement and validate it for the exact capability in question; do not copy the illustrative name as a working test.

Handle asynchronous tests deliberately

Do not treat an asynchronous result as though it were available in a synchronous branch. The project documents Modernizr.on(feature, callback) for asynchronous tests; the callback runs once for each registration. For a custom asynchronous test that needs tighter control, the README recommends addTest.

Modernizr.on("examplefeature", function (supported) {
  if (supported) {
    enableEnhancedExperience();
  } else {
    enableFallbackExperience();
  }
});

Use this pattern only when the selected test is asynchronous. Synchronous tests should be checked synchronously. Choose the fallback timing deliberately so the interface does not leave essential content unavailable while waiting.

Decide between a fallback and a polyfill

A fallback changes your app’s behavior or presentation when a capability is missing. A polyfill attempts to supply missing behavior. They solve different problems: Modernizr detects; it does not turn an unsupported feature into a supported one.

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

Before adding a polyfill, independently verify that it implements the exact behavior your app needs and is suitable for your target browsers. The project material cited here does not establish a specific polyfill as current or recommended. Compare the options by asking:

  • Does the detect test the capability the enhanced path truly requires?
  • Can users still complete core tasks through the fallback?
  • What implementation and payload cost do the detect and fallback add?
  • If using a polyfill, does it supply the required behavior in the browsers you support?
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Test the enhanced and fallback paths

The project README describes a test workflow using npm test and browser-served unit and integration pages. Consult the current repository instructions for the exact setup, then run the tests and open the relevant pages in the browsers you choose. For the app itself, test both feature states and the user tasks that depend on them; passing a detect or library test alone cannot establish that your fallback is usable.

Include representative devices and browser versions for your audience rather than claiming universal coverage. Check the app’s content, controls, layout, keyboard and pointer interactions, and any behavior changed by the enhancement.

Troubleshooting

The expected CSS class is missing

  • Confirm the build includes the relevant detect.
  • Check whether your configuration disables classes or changes their prefix.
  • Verify that the generated Modernizr build loads before code or styles that depend on its results.

The JavaScript branch always uses the fallback

  • Check that the property name matches the included detect; custom test names are lowercased on the object.
  • Confirm the detect measures the behavior you need, and that the selected build actually contains it.
  • If the result is asynchronous, wait through the documented callback mechanism instead of reading it too early.

The enhanced experience breaks despite a positive result

  • Recheck that the detect corresponds to the precise API or behavior used by the app.
  • Test the complete feature path in the target browsers; a positive detect is not proof that every application-level assumption is correct.
  • Retain or restore a fallback that keeps essential tasks available.

A build or integration command fails

  • Use the current npm and CLI instructions in the Modernizr repository rather than assuming an older plugin or bundler integration remains maintained.
  • Check the Node.js requirement for the package version you install. The project’s v4 notes specify that Node.js 10 and below are unsupported for that version.

Or skip the browser setup

If the job is capturing a webpage rather than building its browser experience, ScreenshotNeo is a website screenshot API and MCP server. One GET request returns an image or PDF; the following cURL example saves a WebP screenshot. Replace the target URL as needed and use an API key from your account. See the ScreenshotNeo API documentation for request options.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
  • Cookie/consent banners, newsletter popups, and chat widgets are removed before capture; each cleanup step can be turned off.
  • Bot checks/CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing; response headers report the page verdict and billing status.
  • An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents and MCP clients.
  • The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots.

Sign up for ScreenshotNeo and start with 1,000 free screenshots a month, no card required.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.