mrkeyoor.com_
Wed 23 Sept 00:33 UTC
npmUtilsupdated 22 Sept 2026

css-mediaquery review

css-mediaquery 0.1.2 parses old-style CSS3 media queries and evaluates them against a device-state object supplied by your code. Its two exports are `parse()` and `match()`. The package is useful in SSR tests where `window.matchMedia` does not exist, but it cannot observe a viewport or emit change events. Our complete browser build was only 2.3 KB minified and 1.1 KB gzipped. There is no newer release to explain: 0.1.2 was published in January 2014, before range syntax and media features such as `prefers-reduced-motion` became ordinary application requirements.

Verdict

css-mediaquery 0.1.2 installed in 0.7 seconds and bundled to 1.1 KB gzipped in our sandbox, but its last npm release was in 2014. Keep it for compatible CSS3-era SSR tests; do not install it to validate modern browser media queries.

We installed it

Lab card: what happened when we installed css-mediaqueryScreenshot of css-mediaquery documentation
Install✓ · 0.7s1 package on disk · 1 MB
ImportESM import works · require() works · CommonJS package
Browser1.1 KBgzipped (2.3 KB minified), bundled with esbuild
Typesno TypeScript types found
Known vulns00 critical · 0 high · 0 moderate · 0 low (npm audit)

Answers from our run

Does css-mediaquery install cleanly?

Yes. In a fresh container with an empty cache, npm install css-mediaquery finished in 0.7s, leaving 1 package and 1 MB on disk. npm audit reported no known vulnerabilities.

How much does css-mediaquery add to a browser bundle?

1.1 KB gzipped (2.3 KB minified) when the whole package is bundled for the browser with esbuild. Importing only part of it is usually smaller.

Does css-mediaquery work with both ESM and CommonJS?

Yes. Both import 'css-mediaquery' and require('css-mediaquery') worked in Node 22 in our run. The package is published as CommonJS.

Does css-mediaquery include TypeScript types?

No type declarations were found in our install, so TypeScript users need their own declarations.

css-mediaquery or media-query-parser: which should you use?

media-query-parser: Use it when parsing current media-query text matters more than evaluating a fake device state. css-mediaquery 0.1.2 installed in 0.7 seconds and bundled to 1.1 KB gzipped in our sandbox, but its last npm release was in 2014.

When should you not use css-mediaquery?

Your queries include prefers-reduced-motion, any-pointer, color-gamut, or modern comparison syntax; open requests show these gaps

API stability4/5The same 2 functions, `parse()` and `match()`, have defined the package for more than 12 years. The README's AST shape still matches the implementation, so existing integrations rarely face churn. A score of 5 would imply dependable edge behavior: malformed text can throw, zero-valued features have a reported bug, and any future fix to old unit conversions could change established results.
Docs3/5The README gives working examples for both exports, shows the returned AST, says a concrete media type is mandatory, and links the CSS3 specifications it follows. It does not warn that em and rem are fixed at 16px, that `match()` reparses its input, or that current media features and range syntax are absent. Reading the short source and issue list is necessary before using it as a conformance check.
Maintenance1/5npm shows version 0.1.2 published on 2014-01-21. GitHub is not archived, but its last push was 2024-09-13 and GitHub listed 16 open issues and pull requests. Requests cover modern media features, zero handling, calculation failures, and unreleased fixes. A decade without a package release makes the behavior predictable, yet it also means browser standards have moved beyond the implementation.
Ecosystem3/5npm counted 3,697,226 downloads in the week ending 2026-08-24, largely because the tiny matcher sits inside established SSR and testing trees. It has 0 dependencies and just 1 package occupied our install. The ecosystem around the API is thin: no bundled types, plugins, shared PostCSS AST, or event model, so most value comes from compatibility with callers that already depend on it.

Use it if

  • You need the established `match(query, values)` contract inside an older SSR or test dependency
  • Your inputs use Media Queries Level 3 forms such as min-width, orientation, resolution, and comma-separated alternatives
  • A small package-specific AST is sufficient for inspecting one media-query string
  • You can define the simulated media type and every feature value explicitly
Skip it if

Setup reality

Our install of css-mediaquery 0.1.2 completed in 0.7 seconds. It left 1 package and 1 MB on disk; the tarball expands to 32 KB and declares 0 direct dependencies and 0 peers. npm audit found 0 known vulnerabilities. The BSD package is CommonJS without an exports map. require() and ESM import both worked, but no TypeScript declarations were present.

There are no credentials, native builds, or configuration files. Call match(query, values) with a concrete type such as screen or print; the README says type is required and cannot be all. The values object is synthetic. Node does not fill width, resolution, color depth, or orientation for you.

Our namespace browser build measured 2.3 KB minified and 1.1 KB gzipped. That low cost does not make the result browser-equivalent. The code treats em and rem as 16px, has reported problems around zero values and calc(), and only understands the grammar it ships. parse() can throw SyntaxError, and match() calls it internally, so untrusted query strings need an error boundary.

The AST contains query objects with inverse, type, and expression records. There is no public serializer, listener API, or match-from-AST method. An SSR guess of 1,024px can disagree with the client during hydration. Keep that policy visible in tests, and use the real window.matchMedia after the browser owns the page.

Patterns

Evaluate a minimum width match-width

const mq = require('css-mediaquery')

const matches = mq.match('screen and (min-width: 40em)', {
  type: 'screen',
  width: '1024px',
})

The 40em threshold becomes 640px because this package always treats 1em as 16px.

Accept either screen width or print match-query-list

mq.match('screen and (min-width: 900px), print', {
  type: 'print',
  width: '800px',
}) // true

Comma-separated branches use OR semantics; one matching query makes the whole call true.

Compare an explicit orientation match-orientation

mq.match('screen and (orientation: landscape)', {
  type: 'screen',
  orientation: 'landscape',
})

Width and height do not produce orientation automatically. Supply the orientation property yourself.

Normalize resolution units match-resolution

mq.match('(min-resolution: 2dppx)', {
  type: 'screen',
  resolution: '192dpi',
}) // true

The implementation converts 2dppx to 192dpi; include units in fixtures so the assumption remains readable.

Test a minimum aspect ratio match-ratio

mq.match('(min-aspect-ratio: 16/9)', {
  type: 'screen',
  'aspect-ratio': '1.8',
}) // true

Hyphenated feature names need quoted object keys, and ratio strings are converted to decimal numbers.

Inspect parsed expressions parse-ast

const ast = mq.parse('screen and (min-width: 48em)')
console.log(ast[0].type)
console.log(ast[0].expressions[0])

The returned AST is descriptive. Public `match()` still requires the original string and will parse it again.

Return false for malformed syntax handle-invalid-query

function safeMatch(query, values) {
  try { return mq.match(query, values) }
  catch (error) {
    if (error instanceof SyntaxError) return false
    throw error
  }
}

Malformed structure can throw `SyntaxError`; avoid swallowing unrelated conversion or programming errors.

Create a static SSR MediaQueryList shape mock-matchmedia

function ssrMatchMedia(query) {
  return {
    matches: mq.match(query, { type: 'screen', width: '1024px' }),
    media: query,
    onchange: null,
    addListener() {}, removeListener() {},
    addEventListener() {}, removeEventListener() {},
    dispatchEvent() { return false },
  }
}

This 1,024px server assumption never changes and may disagree with the actual client viewport during hydration.

Alternatives

PackageRegistryPick it when
media-query-parsernpmUse it when parsing current media-query text matters more than evaluating a fake device state.
postcss-media-query-parsernpmUse it inside PostCSS transforms that already operate on stylesheet nodes.
matchmediaquerynpmUse it when server-side matching is the only feature and its API better fits the surrounding code.

More utils guides

lru-cache · ajv · type-fest · p-limit · find-up · js-yaml · the whole shelf →

How this guide is made: grounded in the library's documentation, release notes, changelog, and issue history, on a fixed rubric — not a hands-on install of every release. The 50 most-downloaded entries are additionally install-verified in clean containers. Corrections: contact the desk.