Home › Developer Tools › CSS Media Query Generator

CSS Media Query Generator

Pick the conditions you need and get a clean @media rule, with a live check that shows whether it matches your current screen. Or choose a framework to get a complete mobile-first or desktop-first breakpoint skeleton.

Last updated:

Quick start:
Conditions (all must match)
Syntax
Unit
Checking…
Generated CSS

      
Advertisement
Advertisement

How to use the CSS Media Query Generator

  1. Choose a mode: Custom query to build one rule, or Framework breakpoints for a full set.
  2. Add conditions such as min-width 768px, orientation landscape or prefers-color-scheme dark; they are joined with and.
  3. Pick the syntax and unit: classic min/max or range syntax, in px, em or rem.
  4. Type a selector and declarations to wrap them in the rule, and watch the match indicator while you resize the window.
  5. Copy the CSS or download it as a .css file.

Popular framework breakpoints

All values are minimum widths in CSS pixels. The first range of each framework starts at 0.

FrameworkBreakpoints (min-width)Default approach
Bootstrap 5sm 576, md 768, lg 992, xl 1200, xxl 1400Mobile first; max-width uses .98 (767.98px)
Tailwind CSSsm 640, md 768, lg 1024, xl 1280, 2xl 1536Mobile first (v4 writes them as 40rem, 48rem, 64rem, 80rem, 96rem)
Foundation 6medium 640, large 1024, xlarge 1200, xxlarge 1440Mobile first
Bulmatablet 769, desktop 1024, widescreen 1216, fullhd 1408Mobile first
Material UI (MUI)sm 600, md 900, lg 1200, xl 1536Mobile first (theme.breakpoints.up)
Material Design 3medium 600, expanded 840, large 1200, extra-large 1600Window size classes

Media features cheat sheet

FeatureValuesTypical use
min-width / max-widthlengthResponsive layouts based on viewport width
orientationportrait, landscapeShort landscape phones, kiosk screens
min-resolution2dppx (= 192dpi)Serving sharper images to high-density screens
hover / pointerhover, none / fine, coarse, noneHover effects only for mouse users; larger tap targets for touch
prefers-color-schemelight, darkDark theme that follows the system setting
prefers-reduced-motionreduce, no-preferenceTurning off animations for people who asked for less motion
prefers-contrast / forced-colorsmore, less / activeHigh contrast and Windows contrast themes
display-modestandalone, fullscreen, minimal-ui, browserStyles for an installed web app (PWA)

Classic vs range syntax

@media (min-width: 768px) and (max-width: 1023.98px) and @media (768px <= width < 1024px) select the same screens. The range form is shorter, supports strict < so you no longer need the .98 trick, and works in Chrome and Edge 104+, Firefox 63+ and Safari 16.4+. In em units, the generator divides pixel values by 16, the default browser font size used for media queries.

Frequently asked questions

What is a CSS media query?

A media query applies a block of CSS only when the device or browser matches certain conditions, such as a minimum viewport width, a landscape orientation or a dark color scheme preference. It is written as @media followed by the conditions and a block of rules.

Should I use min-width or max-width?

With a mobile-first approach you write base styles for small screens and add min-width queries for larger ones; this is what Bootstrap and Tailwind do. Desktop-first uses max-width queries to override desktop styles on smaller screens. Both work; mobile-first usually produces less CSS overriding.

Why does Bootstrap use 767.98px instead of 767px?

Browsers can report fractional widths on high-density screens and when zoomed. A max-width of 767px would leave a gap between 767 and 768px where neither query matches; 767.98px closes that gap while still not overlapping min-width: 768px.

What is the media query range syntax?

Media Queries Level 4 allows comparisons like (width >= 768px) or (400px <= width <= 700px) instead of min-width and max-width. It is supported in all current major browsers since 2023; use the classic syntax if you still need to support older browsers.

Should breakpoints be in px or em?

Both work in modern browsers. em-based media queries are relative to the browser's default font size (usually 16px), so they scale if a user raises their default text size. rem behaves the same as em inside media queries.

How do I detect dark mode with CSS?

Use @media (prefers-color-scheme: dark) { … }. It matches when the operating system or browser is set to a dark theme. Also add the color-scheme property or meta tag so built-in controls and scrollbars match.

What does @media (hover: hover) do?

It matches devices whose primary input can hover, such as a mouse or trackpad. Wrapping hover effects in it avoids sticky hover states on touch screens. Use (any-hover: hover) to check any connected input instead of the primary one.

Are all the tools on FreeToolCabin tested for quality and accuracy?

Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

Related tools

CSS Grid GeneratorDraw CSS grid layouts: set tracks and gaps, drag to name areas, then copy the CSS and HTML.CSS Flexbox GeneratorBuild flexbox layouts visually: set container and item properties, then copy the CSS and HTML.PX to REM ConverterConvert px to rem or em and back, with a 1-100px table and a whole-CSS converter.What Is My Screen ResolutionSee your screen resolution, viewport, pixel ratio, colour depth and display features.Open Graph PreviewPaste OG tags and preview how links look on Facebook, X and LinkedIn.YouTube Embed Code GeneratorCreate responsive YouTube embed code with start time, autoplay, loop and privacy mode.CSS Box Shadow GeneratorDesign layered CSS box shadows with a live preview, presets and one-click Copy CSS.CSS Border Radius GeneratorRound each corner, draw elliptical 8-value radii or random blob shapes and copy the CSS.CSS Button GeneratorDesign CSS buttons with gradients, borders, shadows and hover and active states, then copy the code.Twitter Card GeneratorCreate X / Twitter Card meta tags with Open Graph fallbacks, character counters and a live preview.Glassmorphism CSS GeneratorDesign frosted-glass UI cards with blur, transparency and border sliders, then copy the CSS.CSS Text Shadow GeneratorLayer CSS text shadows with a live preview and neon, 3D, outline and retro presets.HTML Editor (Live Preview)Write HTML, CSS and JavaScript and see a live, sandboxed preview as you type.HTML to JSX ConverterConvert HTML to valid React JSX: className, htmlFor, style objects, self-closing tags and events.CSS Clip-Path GeneratorDraw CSS clip-path shapes by dragging points: polygons, circle, ellipse and inset. Copy the CSS.CSS Animation GeneratorCreate CSS keyframe animations from 23 presets with live preview, timing controls and Copy CSS.CSS Triangle GeneratorMake CSS triangles in 8 directions with the border trick or clip-path. Set size and color, copy CSS.CSS Loader GeneratorPick from 14 pure CSS spinners and loaders, set color, size and speed, then copy the HTML and CSS.Cubic Bezier GeneratorDrag the control points to design a CSS easing curve, compare it with linear and copy cubic-bezier().CSS Filter GeneratorAdjust blur, brightness, contrast, hue, sepia and drop-shadow on an image and copy the CSS filter.CSS Specificity CalculatorCalculate CSS selector specificity (a, b, c), including :is(), :not(), :has() and :where(), and compare.Google Maps Embed GeneratorTurn an address or coordinates into responsive Google Maps iframe embed code, no API key.Neumorphism CSS GeneratorDesign soft UI neumorphic shapes with live preview and copy the box-shadow CSS.SVG Wave GeneratorMake layered SVG waves for section dividers and export SVG, PNG or a CSS background.SVG Blob GeneratorGenerate random organic SVG blob shapes with gradients and export SVG, PNG or CSS clip-path.CSS Clamp GeneratorTurn min/max sizes and viewport widths into a fluid CSS clamp() value in rem and vw.CSS @font-face GeneratorTurn font files or URLs into ready-to-paste @font-face rules with weights, styles and a preview.CSS Scrollbar GeneratorStyle scrollbars: width, colors, radius and hover, with ::-webkit-scrollbar and scrollbar-color CSS.CSS Sprite GeneratorPack many icons into one sprite sheet PNG and get CSS classes with background-position.CSS Text Gradient GeneratorMake gradient text with background-clip:text: color stops, angle, font preview and fallback CSS.CSS Toggle Switch GeneratorDesign pure-CSS toggle switches: size, colors, shape and animation. Copy accessible HTML + CSS.CSS Tooltip GeneratorBuild pure CSS tooltips: position, arrow, colors, padding and animation. Copy HTML and CSS.HTML Form BuilderDrag and drop form fields with labels and validation, then copy accessible HTML and CSS code.Iframe GeneratorCreate iframe embed code: size or responsive ratio, border, allow, sandbox, lazy load, live preview.PX to VW ConverterConvert pixels to vw and vh for any viewport size, and vw/vh back to px, with breakpoint tables.SVG Path EditorEdit an SVG path d attribute visually: drag points, edit commands, convert, scale and minify.SVG to CSS Data URITurn SVG code into a small URL-encoded data URI for CSS backgrounds, with Base64 size comparison.SVG to JSXTurn SVG code into a clean React component: camelCase attributes, style objects, TypeScript.CSS Shape Divider GeneratorCreate wave, tilt, curve and triangle section dividers and copy the SVG, HTML and CSS.CSS Transform GeneratorRotate, scale, skew and translate an element with sliders and copy the CSS transform code.Font Pairing ToolPreview Google Font heading and body pairs on real layouts and copy the embed code and CSS.HTML Accessibility CheckerPaste HTML to find WCAG accessibility problems with impact level, the failing element and a fix.HTML Image Map GeneratorDraw clickable rectangle, circle and polygon hotspots on an image and get image map HTML.SVG ViewerOpen or paste SVG code to preview it live with zoom, backgrounds, size info and PNG export.Pathfinding VisualizerAnimate BFS, DFS, Dijkstra, A* and greedy search on a grid with walls, weights and mazes.Tailwind CSS Cheat SheetSearchable Tailwind class to CSS reference with live previews, class decoder and color palette.Web App Manifest GeneratorCreate a PWA manifest.json and every app icon size from one image, downloaded as a ZIP.CSS Background Pattern GeneratorMake pure-CSS stripes, dots, checkerboard, zigzag and grid backgrounds and copy the code.CSS Color Filter GeneratorTurn a HEX color into a CSS filter that recolors black icons and SVGs, with an accuracy score.CSS Gradient Animation GeneratorCreate animated gradient backgrounds: pick colors, angle and speed, preview live and copy the CSS.CSS Hover Effects GeneratorPick button, link and image hover effects, tweak colors and timing, and copy the HTML and CSS.CSS InlinerMove CSS from style blocks into inline style attributes so HTML emails render in every client.
See all 52 Web, HTML & CSS Tools →