CSS media query generator

Build a CSS media query for min-width, max-width, a width range or reduced motion, preview the matched and unmatched layout, then copy the finished CSS. The generator writes the base rule and the @media block together, so the result is ready to paste into your stylesheet.

How do you write a CSS media query?

Write @media (min-width: 768px) { ... } and put the rules that should change inside the braces. The browser applies them only when the viewport matches the condition. This generator adds the base rule first, then the media block, so the layout has a sensible default at every width.

  1. Pick min-width, max-width, range or prefers-reduced-motion.
  2. Set the pixel widths, or turn on reduced motion to preview the static state.
  3. Drag the preview viewport to watch the query match and stop matching.
  4. Click Copy CSS and paste the rule into your stylesheet.
Query type

Live preview

1
2
3
4

At 1024px the query matches, so the grid uses repeat(2, minmax(0, 1fr)).

Generated CSS

.demo-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 768px) {
  .demo-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

Which breakpoints should you start with?

These are common starting points, not fixed device rules. Add a breakpoint where your own content breaks, and keep the same set across the site so the CSS stays predictable.

NameMin-widthMax-widthTypical use
Small phone0px639pxSingle column, stacked cards, full-width buttons.
Large phone640px767pxTwo small columns, wider form fields.
Tablet768px1023pxTwo-column grids, visible side navigation.
Laptop1024px1279pxThree-column grids, persistent sidebar.
Desktop1280px1535pxWider content, larger gaps and type.
Wide desktop1536pxand upMax-width container, extra whitespace.

Mobile-first or desktop-first?

Mobile-first CSS starts with the smallest layout and uses min-width queries to add columns and spacing as the screen grows. Desktop-first CSS starts with the full layout and uses max-width queries to simplify it. Both work, but mobile-first usually means less CSS because the base styles serve the most constrained screen and each query only adds what the wider viewport needs.

Which related CSS tools help with responsive layout?

Frequently asked questions

What is a media query in CSS?

A media query is a CSS rule that applies styles only when the browser or device matches a condition, such as a minimum viewport width or a reduced-motion preference. Write @media (min-width: 768px) { ... } and the rules inside only take effect at 768px and wider.

What is the difference between min-width and max-width?

min-width applies at or above a width, so it is the usual choice for mobile-first CSS that adds layout as the screen grows. max-width applies at or below a width, so it suits desktop-first CSS that removes or simplifies layout on smaller screens. Use one direction consistently to avoid conflicting overrides.

How do I write a range media query?

Combine two conditions with and: @media (min-width: 768px) and (max-width: 1023px) { ... }. The rules apply only while the viewport is between those two widths. Modern browsers also accept the range syntax @media (768px <= width <= 1023px), but the min-width and max-width form works everywhere.

What is prefers-reduced-motion?

prefers-reduced-motion is a media feature that reports whether the visitor has asked their operating system to reduce animation. Wrap large movement, parallax or looping animation in @media (prefers-reduced-motion: reduce) and replace it with a static state or a short fade so the page stays comfortable to use.

What breakpoints should I use?

Start from your content rather than a fixed device list. Common starting points are 640px for large phones, 768px for tablets, 1024px for laptops and 1280px for wide desktops. Add a breakpoint only where the layout actually breaks, and keep the same set across the site so the CSS stays predictable.

Do media queries affect SEO?

Media queries do not change the HTML or the text a crawler reads, so they are not a ranking factor by themselves. They do affect mobile usability, layout shift and how quickly a visitor can read the page, which feed into the page experience signals Google and Bing use.

More CSS generators

Color tools

Image tools

Image & SVG tools

Typography & units

More free tools

All free tools