Modernizr checks which native HTML5 and CSS3 capabilities the current browser supports. Results are exposed on a global object and as classes on the document element for progressive enhancement.
Overview
Modernizr is a JavaScript library that probes the user agent for HTML5 and CSS3 feature support. It reports findings both as properties on a global Modernizr object and as classes on the root element, so pages can adapt behavior and styling with fine-grained control.
Version 4 removed support for node version classes and limits event handling on asynchronous tests; synchronous tests are meant to run synchronously for speed and consistent behavior. Custom detections can be added via src/addTest, which ties into the library’s callback API.
Consumers can install the package from npm and generate tailored builds programmatically or through a command-line interface. Options and feature detects are configured via JSON; a full option list is available in the project’s config-all.json.
Documentation covers wiring Modernizr into Webpack, Gulp, and Parcel, including custom config files and plugins where applicable.
Key features
- HTML5 and CSS3 feature detects
- Global Modernizr object API
- Root element CSS classes for support
- Custom build via npm or CLI
- Programmatic build with JSON options
- src/addTest for custom detects
- Webpack, Gulp, and Parcel integration
Use cases
- Progressive enhancement by browser capability
- Conditional CSS and JavaScript loading
- Custom minimal feature-detect builds
- Build-pipeline browser capability checks