paulirish/matchMedia.js
paulirish/matchMedia.js has 2,358 GitHub stars and 273 forks. GitHot measured 0 stars in 24 hours. Last checked 2026-11-06 22:33 UTC. Last push 2020-12-22.
matchMedia polyfill for testing media queries in JS
Measured star growth
- in 24h
- 0
- in 7 days
- Collecting history
- in 15 days
- Collecting history
- in 1 month
- Collecting history
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
README.md
OriginalmatchMedia() polyfill
test whether a CSS media type or media query applies
Usage
// Likely want to requier both polyfills..
require('matchmedia-polyfill');
require('matchmedia-polyfill/matchMedia.addListener');
test 'tv' media type
if (matchMedia('tv').matches) {
// tv media type supported
}
test a mobile device media query
if (matchMedia('only screen and (max-width: 480px)').matches) {
// smartphone/iphone... maybe run some small-screen related dom scripting?
}
test landscape orientation
if (matchMedia('all and (orientation:landscape)').matches) {
// probably tablet in widescreen view
}
Used in:
How about resizing the browser?
Paul Hayes tackled this using CSS transitions and their transitionEnd event
His code: https://github.com/fofr/matchMedia.js -- though currently it doesnt support IE6-9, since they dont have transitions, obviously. :)
- Authors: Scott Jehl, Paul Irish, Nicholas Zakas
- Spec: dev.w3.org/csswg/cssom-view/#dom-window-matchmedia
- Native support: Chrome since m10, Firefox since 6, and Safari since 5.1
Explore related projects
codecrafters-io/build-your-own-x
Master programming by recreating your favorite technologies from scratch.
560,478 starspublic-apis/public-apis
A collective list of free APIs
496,785 starsmorluto/rea
Reverse engineer anything with agents, from app behavior down to native binaries.
438,437 starsopenclaw/openclaw
The AI that really does things. Any OS. Any Platform. The lobster way. 🦞
394,086 stars