CSS Media Query Generator - Online Quick Syntax Builder
Build a CSS media query by selecting feature, operator, and value. Copy the exact syntax for your stylesheet.
UD5 Toolkit
Validate your CSS media query syntax instantly. Paste your @media rules and get detailed feedback, structure breakdown, and error diagnostics.
A CSS media query is a conditional statement that applies styles only when certain conditions about the user's device or browser are met. It's the foundation of responsive web design, allowing you to adapt layouts based on viewport width, height, orientation, resolution, color scheme preferences, and many other device characteristics. The basic syntax is @media [media-type] and (feature: value) { /* CSS rules */ }.
The most frequently used media features include: width / min-width / max-width (viewport width), height / min-height / max-height (viewport height), orientation (portrait or landscape), prefers-color-scheme (light or dark), hover (none or hover), pointer (none, coarse, or fine), resolution (dpi, dpcm, dppx), and prefers-reduced-motion (reduce or no-preference). Modern CSS also supports range syntax like (width >= 768px).
and combines multiple conditions that must ALL be true (logical AND). For example: @media screen and (min-width: 768px) and (max-width: 1024px) applies only when all three conditions are met. Comma (,) acts as a logical OR — if ANY of the comma-separated queries match, styles are applied. Example: @media screen, print matches either screen or print devices. The newer or keyword (Media Queries Level 4) works similarly to comma but within a single query: @media (min-width: 768px) or (orientation: landscape).
only is used to hide media queries from older browsers that don't support media features. An older browser sees only screen and ... and, not recognizing 'only', ignores the entire block. Modern browsers ignore the 'only' keyword and process the query normally. not negates the entire media query, applying styles when the query would NOT match. For example: @media not screen and (max-width: 600px) applies to everything EXCEPT screens narrower than 600px. Note that not inverts the entire query, not just the media type.
In mobile-first design, you write base styles for the smallest screens first, then use min-width queries to add complexity at larger breakpoints. Common breakpoints: @media (min-width: 576px) for small devices, @media (min-width: 768px) for tablets, @media (min-width: 992px) for desktops, and @media (min-width: 1200px) for large desktops. This approach ensures your site works on all devices and progressively enhances the experience on larger screens. Avoid using max-width as your primary strategy — it's harder to maintain and less future-proof.
Yes! The prefers-color-scheme media feature detects the user's system color theme. Use @media (prefers-color-scheme: dark) to apply dark mode styles, and @media (prefers-color-scheme: light) for light mode. You can also combine it with other conditions: @media screen and (prefers-color-scheme: dark) and (min-width: 768px). This feature is widely supported in all modern browsers and is essential for creating accessible, user-friendly websites that respect system preferences.
Common media query mistakes include: 1) Missing or mismatched parentheses — every media feature must be in its own parentheses. 2) Forgetting the colon between feature name and value, e.g., (min-width 768px) instead of (min-width: 768px). 3) Missing units on values — (min-width: 768) is invalid; it must be (min-width: 768px). 4) Using max-device-width (deprecated) instead of max-width. 5) Incorrect operator usage — and must connect complete feature queries. 6) Spelling errors in feature names like preferes-color-scheme. Our validator catches all these errors!
Media Queries Level 4 introduced range syntax using comparison operators, making queries more readable. Instead of (min-width: 768px) and (max-width: 1024px), you can write (768px <= width <= 1024px) or (width >= 768px) and (width <= 1024px). Supported operators include <, <=, >, >=, and =. This syntax is supported in all modern browsers (Chrome 104+, Firefox 102+, Safari 16.4+). It's especially helpful for complex range conditions and improves code readability significantly.
Build a CSS media query by selecting feature, operator, and value. Copy the exact syntax for your stylesheet.
Write a media query and instantly see if it matches your current viewport. Width, height, orientation, and more.
Paste media queries and see a visual indicator of which rules apply at current viewport size.
Test the new style() function inside @container to query custom property values. Revolutionary component‑based responsive design.
Start from a base color and use `oklch(from color l c h)` to create lighter or darker variants. Copy the code.
Write a media query and see if it matches as you resize the iframe. Understand width, height, and resolution queries.
Toggle between light and dark mode for a demo page. See how to use the media query. Copy the pattern.
Experiment with CSS container queries in a live editor. Resize the container and see styles change based on its width/height. Learn modern responsive.
Experiment with the CSS color-mix() function. Pick two colors and mix them in different color spaces (srgb, oklch). Copy the CSS.
Upload ugly SQL and get a beautifully indented, syntax‑highlighted version. Supports multiple dialects. All local.
Combine aspect‑ratio with min‑/max‑width/height and see how the box responds. Understand sizing constraints. Copy the pattern.
Format and beautify SQL queries for improved readability. Supports various SQL dialects. Quick syntax highlighting and local processing ensure a secure experience.
Toggle image‑rendering: auto, pixelated, crisp‑edges on a scaled image. Essential for pixel art display.
Interactively apply CSS filter functions (blur, brightness, contrast, etc.) to an image and copy the resulting filter property. No coding required.
See how your title and meta description will be truncated in Google SERP by pixel width. Optimize click‑through.
Browse the OKLCH color space with sliders for lightness, chroma, and hue. See the CSS oklch() code. Modern and accessible.
Drop an image that might have wrong extension and see its real format (JPEG, PNG, WebP) based on header bytes.
Compare break‑all, keep‑all, and overflow‑wrap: anywhere/break‑word. Paste long words and see how they wrap.
Simulate reduced motion preference and test your animations. Copy the media query snippet. Keep your users safe.
Place a table caption on top, bottom, or inline‑start/end. See the live change. Copy the code.
Wrap text around an irregular shape and adjust the margin and alpha threshold. Magazines layout on the web.
Upload an image at multiple widths and generate a complete <picture> or <img srcset> snippet. Modern web performance.
Increase or decrease the color saturation of your photo with a slider. Preview instantly. Download the edited image. Canvas‑based.
Enter foreground and background colors to instantly see the contrast ratio and pass/fail for AA and AAA. Simple and fast.
Enter a website URL and apply a protanopia/deuteranopia/tritanopia filter. Test full page accessibility.
Create a responsive box that maintains a specific aspect ratio using the aspect‑ratio property. Copy the simple CSS.
Preview how your page title will appear in Google SERPs. See pixel width and character count. Avoid truncation. Free local tool for SEOs.
Drag a virtual ruler across your screen to measure pixel distances. Horizontal and vertical guides. Useful for UI designers checking alignment.
Enter the URL of any online image and extract its dominant colors or pick colors with a magnifier. No upload, cross‑origin friendly.
Visually name grid areas in a table and generate grid‑template‑areas CSS. Perfect for complex layouts. Drag‑free.