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.
Interactively create colors in HWB space and get the CSS hwb() function. Simplifies tint/shade workflows. Live preview.
Toggle image‑rendering: auto, pixelated, crisp‑edges on a scaled image. Essential for pixel art display.
Upload ugly SQL and get a beautifully indented, syntax‑highlighted version. Supports multiple dialects. All local.
See how your title and meta description will be truncated in Google SERP by pixel width. Optimize click‑through.
Write a media query and see if it matches as you resize the iframe. Understand width, height, and resolution queries.
Enter foreground and background colors to instantly see the contrast ratio and pass/fail for AA and AAA. Simple and fast.
Construct a CSS‑only carousel with scroll‑snap and scroll‑driven animations. Configurable gap, items, and progress indicator. Copy the HTML/CSS.
Reduce GIF file size by lowering color count and removing duplicate frames. See side‑by‑side preview. All local.
Create a responsive box that maintains a specific aspect ratio using the aspect‑ratio property. Copy the simple CSS.
Paste image URLs and generate a responsive masonry or justified gallery layout with lightbox. Copy the HTML/CSS/JS.
Detect your current screen resolution, viewport dimensions, and device pixel ratio. Useful for responsive design testing. No data collection.
Upload an image at multiple widths and generate a complete <picture> or <img srcset> snippet. Modern web performance.
Design a layout where nested grids share track sizes with their parent via subgrid. Copy the complete CSS.
Pick colors from a palette or use the eye dropper to sample colors from your screen. Converts between HEX, RGB, HSL. An essential tool for designers.
Upload a small pixel art image and get a CSS grid layout that recreates it using divs. Novelty developer tool.
Upload two images and see a diff overlay highlighting the pixel differences. Adjust tolerance. For regression testing.
Convert video files between common formats using FFmpeg WASM. No upload required; all processing stays in your browser.
Browse the OKLCH color space with sliders for lightness, chroma, and hue. See the CSS oklch() code. Modern and accessible.
Enter the URL of any online image and extract its dominant colors or pick colors with a magnifier. No upload, cross‑origin friendly.
Increase or decrease the color saturation of your photo with a slider. Preview instantly. Download the edited image. Canvas‑based.
A horizontal photo gallery that scrolls with a smooth CSS animation using scroll‑timeline. Pure HTML/CSS. Copy the code.
Upload an image and extract its dominant colors or full color palette. Download as a CSS snippet or color swatch. Entirely client-side, your images stay private.
Enter a website URL and apply a protanopia/deuteranopia/tritanopia filter. Test full page accessibility.
Preview how your page title will appear in Google SERPs. See pixel width and character count. Avoid truncation. Free local tool for SEOs.
Convert illuminance units: lux, foot-candle, phot. Useful for lighting design and photography. Quick and free.
Pixelate or censor parts of an image by dragging. Adjust block size for mosaic effect. Useful for hiding faces or sensitive data. Client-side processing.
Paste text or drop a file and get checksums in multiple formats simultaneously. Compare with original. All local.