Media Query Generator

What Is a CSS Media Query?

CSS media queries are conditional rules that apply styles only when specific criteria are met — most commonly screen width. They're the foundation of responsive web design, letting a single codebase adapt to phones, tablets, laptops, and desktops. This tool generates media query syntax with device presets, breakpoint visualizer, and framework-specific breakpoints for Bootstrap, Tailwind, and Material UI.

Mobile-First vs Desktop-First

Mobile-first (min-width) — start with styles for the smallest screen, then add complexity with min-width queries. This is the modern standard because base CSS is lighter and you progressively enhance. Desktop-first (max-width) — start with desktop styles and override downward. Still used in legacy codebases but produces heavier base CSS.

How to Use This CSS Media Query Generator

  1. Choose the query type — Min-width (mobile-first), max-width (desktop-first) or a range with both.
  2. Set the widths and unit — Enter the breakpoint value(s) in px, em or rem, and optionally add a portrait or landscape orientation condition.
  3. Or start from a framework — Copy Bootstrap 5, Tailwind CSS or Material UI's default breakpoints as a set of mobile-first blocks.
  4. Paste the block — The output is an empty @media block; add the rules that should change at that width.
  5. Copy — Copy the query or the whole block into your stylesheet.

The three framework breakpoint sets, side by side

The framework buttons copy each library's default breakpoints as mobile-first min-width blocks. We checked them against each framework's own documentation on October 12, 2026:

FrameworkBreakpoints (min-width)How the framework writes them
Bootstrap 5.3sm 576 · md 768 · lg 992 · xl 1200 · xxl 1400 pxmin-width for mobile-first, and max-width: 767.98px-style values for the "below" direction
Tailwind CSS v4sm 640 · md 768 · lg 1024 · xl 1280 · 2xl 1536 pxIn rem with range syntax: @media (width >= 48rem)
Material UIsm 600 · md 900 · lg 1200 · xl 1536 pxThrough theme.breakpoints.up() / down() helpers

Only 768 px (md in Bootstrap and Tailwind) and 1200 px (xl in Bootstrap, lg in MUI) are shared, and the same name means different widths in different libraries: Tailwind's lg is 1024 px, Bootstrap's is 992 px. If your project already uses one of these frameworks, copy its set so your custom CSS switches at the same widths as the framework's grid. Mixing sets gives you layouts that change in two steps a few dozen pixels apart.

Why Bootstrap writes 767.98px

Classic min-width and max-width are both inclusive, so (min-width: 768px) and (max-width: 768px) both match a viewport exactly 768 px wide. Both rule sets then apply at once. The range mode here builds (min-width: A) and (max-width: B), so when you stack ranges, end each one just below the next start, as Bootstrap does with .98. Bootstrap's documentation gives the reason for the .02: viewports can have fractional widths (on some high-DPI devices, for instance), so the "below" query needs a value just under the next breakpoint rather than a whole pixel below it. Media Queries Level 4 removes the problem with range syntax, (width < 768px), which MDN's compatibility data lists in Chrome and Edge 104, Firefox 102 and Safari 16.4. Most current browsers support it, but older Safari versions and some embedded browsers don't, which is why this tool still writes the classic form.

px, em or rem?

The unit menu offers px, em and rem. Inside a media query, em and rem are not affected by your stylesheet. The Media Queries Level 4 spec bases them on the initial font size, which comes from the browser or the user's own setting (16 px by default), so 48em means 768 px for most visitors. The difference shows up when a user raises the default font size in their browser. An em or rem breakpoint then moves with it, so the layout switches to the narrower design sooner, where the larger text needs it. A px breakpoint does not move. That is why Tailwind v4 moved its breakpoints to rem.

Frequently Asked Questions

How do I choose breakpoints that fit my own content?
The honest answer is that the device-width breakpoints (480, 768, 1024, 1440) are not the right answer for every site — they are a starting point. The better discipline is to resize the actual content of the page in a browser window from 320 pixels wide upward until something visibly breaks (a navigation item wraps awkwardly, a card grid leaves a single orphan, a heading line-breaks ugly), and write the breakpoint at that pixel value. Most sites need three to five breakpoints, not eight, and the values are unique to the layout rather than copied from a framework. Container queries (now widely supported) make a lot of these older media-query patterns unnecessary for component-scoped responsiveness.
When does min-width produce different results than max-width?
When you mix both styles in a single stylesheet without realizing it, or when you nest min and max ranges so they overlap. A min-width 768px rule applies from 768 pixels upward to infinity; a max-width 767px rule applies from zero up to 767. These two complement each other cleanly. The trouble starts when a project mixes mobile-first (min-width chains) and desktop-first (max-width chains) in different stylesheets — the cascade order becomes the deciding factor at every breakpoint boundary, and small refactors silently flip which rule wins. Pick one direction per project and stick with it.
What is a CSS media query?+
A media query is a CSS technique that applies styles conditionally based on device characteristics — primarily viewport width. The syntax @media (min-width: 768px) { ... } applies enclosed styles only when the viewport is 768px or wider. Media queries are the foundation of responsive web design.
When does a desktop-first breakpoint strategy beat a mobile-first one?+
Mobile-first is the established default and is right for almost every greenfield project — you write the smallest-viewport rules unconditionally, then layer in larger-viewport rules with min-width queries. Desktop-first (max-width chains) earns its keep in two specific contexts. First, when you are progressively retrofitting an existing desktop-heavy site for smaller screens without rewriting the entire stylesheet; max-width queries let you cap legacy layout at the right viewport and apply a slimmer set of rules below. Second, on internal tools and admin dashboards where mobile use is rare and the bulk of the design work is happening at desktop sizes; writing the desktop rules first matches how the team actually thinks about the product. Outside those, default to mobile-first.
What is mobile-first vs desktop-first CSS?+
Mobile-first starts with mobile styles as defaults and adds complexity with min-width queries as the screen grows. Desktop-first starts with desktop styles and removes features with max-width queries for smaller screens. Mobile-first is the industry standard because it produces simpler code and loads fewer styles on bandwidth-constrained mobile devices.
What are standard responsive breakpoints?+
Common breakpoints: 640px (small phones), 768px (tablets), 1024px (laptops), 1280px (desktops), 1536px (large screens). Tailwind CSS and Bootstrap use similar values. However, design your breakpoints around your content, not specific devices.
Can mixing min-width and max-width queries cause conflicts?+
When you mix both styles in a single stylesheet without realizing it, or when you nest min and max ranges so they overlap. A min-width 768px rule applies from 768 pixels upward to infinity; a max-width 767px rule applies from zero up to 767. These two complement each other cleanly. The trouble starts when a project mixes mobile-first (min-width chains) and desktop-first (max-width chains) in different stylesheets — the cascade order becomes the deciding factor at every breakpoint boundary, and small refactors silently flip which rule wins. Pick one direction per project and stick with it.
Should I write media queries for screen size or for content needs?+
Use content-driven breakpoints, not device-driven ones. Pick the viewport width at which your layout starts to look bad (a sidebar wraps under the main content, a card grid becomes a single column, a headline overflows) and write the media query there. Hard-coding popular phone or tablet widths makes the design fragile to new device sizes; writing breakpoints where your specific design breaks makes it robust forever.

📖 Learn More

Related Article CSS Media Queries & Breakpoints Guide →

Built by Derek Giordano · Part of Ultimate Design Tools

Privacy Policy · Terms of Service