How to use the media query generator
- Choose @media or @container.
- Set the width range. Use 0 for “no minimum” or “no maximum”. Pick px or em for media queries.
- Pick the syntax: modern range or classic min/max.
- Add media features such as orientation, color scheme, reduced motion, hover, pointer and contrast.
- Check the live result: the preview says whether the query matches this window now.
- Export CSS, a Tailwind arbitrary variant or a
matchMedia()snippet for JavaScript.
Mobile-first breakpoints
Write base styles for small screens, then add min-width queries for larger ones:
.layout { display: block; }
@media (width >= 768px) { .layout { display: grid; grid-template-columns: 1fr 2fr; } }
Common breakpoints are 640, 768, 1024, 1280 and 1536px, but the best ones are where your own layout starts to look wrong.
How it works
A media query applies CSS only when its conditions are true. You set a minimum width, a maximum width or both, and the generator writes them in the classic form (min-width: 768px) or the newer range syntax (width >= 768px). You can add conditions for orientation, color scheme, reduced motion, hover and pointer capability and contrast preference, which are joined with and. Switching the type to a container query writes an @container rule for a named container instead.
Worked examples
Example 1: dark mode
Load Dark mode: @media (prefers-color-scheme: dark). Swap your color custom properties inside it, and the whole site follows the system setting.
Example 2: reduced motion
Load Reduced motion and put animation: none; transition: none for decorative motion inside. This should be on every site that animates.
Example 3: a responsive card component
Load Card container: the wrapper becomes a container named card, and @container card (inline-size >= 400px) switches the card to a horizontal layout wherever it has room, in a sidebar or a full-width section.
Common mistakes
- Overlapping ranges.
max-width: 768pxandmin-width: 768pxboth match at exactly 768px; use 767px or range syntax. - Desktop-first overrides everywhere. Mobile-first CSS is usually shorter.
- Ignoring preferences. Reduced motion and dark mode are as important as screen size.
Choosing breakpoints
Start with your content, not device lists. Make the window narrow, widen it slowly, and add a breakpoint where a line becomes too long, a grid looks empty or navigation runs out of space. Name breakpoints by size (md, lg) rather than devices, since new devices appear every year.
Remember that browser zoom changes the effective width. A visitor zooming to 200% on a laptop may get your tablet layout, which is exactly what should happen, so make sure every layout works at every width, not just at the breakpoints themselves.