CSS Media Query Builder

Builds a ready-to-paste @media rule from width and height limits, orientation, colour scheme, reduced motion, hover, pointer, resolution and contrast, in classic or modern range syntax.

Use the tool

Why this tool exists

Media queries look simple until you need several conditions together. Is it min-width or max-width? Does a 1023px limit leave a gap at 1023.5px? What is the exact spelling of the dark mode or reduced motion feature? This builder lets you set the conditions with fields and menus and returns the finished rule, so you do not have to remember the syntax. You can write it the classic way or with the newer range form such as 640px <= width <= 1023.98px. If you paste some CSS it wraps it inside the rule, and the output also includes a matchMedia call for testing the same query in JavaScript. Everything runs in the page.

How to use it

  1. Pick the media type and enter the min and max width or height you need.
  2. Add optional conditions: orientation, colour scheme, motion, hover, pointer, resolution or contrast.
  3. Choose classic or range syntax, optionally paste CSS to wrap, and copy the rule.

Frequently asked questions

What is the difference between classic and range syntax?

Classic uses (min-width: 640px) and (max-width: 1023px). Range syntax writes (640px <= width <= 1023px), which reads more naturally. Range syntax is newer, so check support for your target browsers.

Why does the default max width end in .98?

It avoids overlapping with a min-width of 1024px in the next rule. Fractional pixel widths exist on high-density screens, so 1023.98px leaves no gap between ranges.

What values does it accept for sizes?

Numbers with px, em, rem, vw, vh, ch, cm, mm, in or pt. Anything else gives an error. Resolution is entered as a plain number of dppx.

What does the matchMedia line do?

It gives the same query as a JavaScript string so you can test it in the console or use it in code to react to the condition.