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.
Design a layout where nested grids share track sizes with their parent via subgrid. Copy the complete CSS.
Paste your CSS and see warnings for properties that have limited browser support. Links to CanIUse. Modernize safely.
Limit browser gestures on an element: pan‑x, pinch‑zoom, manipulation. Draw on a canvas to test. Mobile dev helper.
Paste any DNS record and check if its format is valid for the selected record type (A, AAAA, CNAME, MX, TXT, SRV). Prevents typos.
Create complex linear gradients with any number of color stops, exact angles, and length units. Live preview and CSS code.
Style underlines, overlines, and strike-throughs with colors, wavy styles, and thickness. Modern CSS text‑decoration.
Design a button or card that glows on hover. Adjust shadow color, spread, and transition. Copy the CSS. Rich UI.
Create a realistic letterpress (debossed) text effect using CSS text‑shadow and background. Adjust depth and light direction. Copy code.
Validate ISBN‑10 and ISBN‑13 numbers and compute their check digits. Useful for booksellers and libraries. All local.
Generate a subtle noise/grain texture as a CSS background pattern. Adjust opacity and size. For that film look.
Create a customizable checkerboard or grid background using pure CSS gradients. Adjust cell size and colors. Copy the code.
Upload two images and apply CSS blend modes (multiply, screen, overlay, etc.). See the result and copy the filter CSS. Pure frontend.
Paste a test card number to verify Luhn algorithm, identify issuer (Visa, MC), and check length. No real data.
Create a pure CSS countdown timer with a flipping number effect. Adjust duration and style. No JavaScript needed for display.
Create a glowing or rotating border animation around an element. Copy the CSS keyframes. Pure CSS magic.
Create a custom HTML/CSS progress bar with percentage, colors, and animation. Copy the code. Modern UI element.
Validate if a version string follows SemVer 2.0.0. Also sort and compare versions. Developer tool.
Design a realistic neon sign text with multiple layers of glow. Copy the CSS and HTML. Perfect for headers.
A replica of the famous Flexbox Froggy game: solve alignment puzzles by writing CSS. Progress saved locally. Fun frontend learning.
Fetch a website's CSS and extract :root custom properties (‑‑color) to reveal its design token palette. For learning and inspiration.
Paste a list of numbers to visually check uniformity, mean, and simple pattern analysis. Educational tool for statistics and RNG.
Recreate the target CSS linear gradient by adjusting stops and colors. A unique game for front‑end developers to master gradients.
Browse and search all Font Awesome 6 icons with preview, class name, and unicode. Copy the HTML snippet. Perfect for web developers.
Create text with a gradient fill using CSS background-clip. Configure colors and direction. Copy the code. Works in modern browsers.