How Media Query Generator works
Pick an approach and a breakpoint set and this tool writes the @media blocks for you, ready to paste and fill in. Mobile first gives min-width queries, such as @media (min-width: 768px). Desktop first gives max-width queries that end 0.02px below each breakpoint, such as @media (max-width: 767.98px), so neighbouring rules never both apply or both miss. Range gives one query between two widths. The built-in sets are Tailwind (640, 768, 1024, 1280, 1536) and Bootstrap (576, 768, 992, 1200, 1400), and Custom takes your own number. You can add an orientation condition, switch the output to em, and include ready blocks for dark mode, reduced motion and print.
Tailwind breakpoints as CSS media queries
The widths in the Tailwind set, with the query the tool writes for each approach and the same width in em.
| Name | Width | Mobile first (min-width) | Desktop first (max-width) | Width in em |
|---|---|---|---|---|
| sm | 640px | @media (min-width: 640px) | @media (max-width: 639.98px) | 40em |
| md | 768px | @media (min-width: 768px) | @media (max-width: 767.98px) | 48em |
| lg | 1024px | @media (min-width: 1024px) | @media (max-width: 1023.98px) | 64em |
| xl | 1280px | @media (min-width: 1280px) | @media (max-width: 1279.98px) | 80em |
| 2xl | 1536px | @media (min-width: 1536px) | @media (max-width: 1535.98px) | 96em |
Tailwind v4 defines its default breakpoints in rem (40rem to 96rem), which equal the pixel widths above at a 16px default font size. Tailwind v3 listed the same widths in pixels.
Bootstrap breakpoints as CSS media queries
The widths in the Bootstrap set. The max-width values match the ones Bootstrap's own stylesheet uses.
| Name | Width | Mobile first (min-width) | Desktop first (max-width) | Width in em |
|---|---|---|---|---|
| sm | 576px | @media (min-width: 576px) | @media (max-width: 575.98px) | 36em |
| md | 768px | @media (min-width: 768px) | @media (max-width: 767.98px) | 48em |
| lg | 992px | @media (min-width: 992px) | @media (max-width: 991.98px) | 62em |
| xl | 1200px | @media (min-width: 1200px) | @media (max-width: 1199.98px) | 75em |
| xxl | 1400px | @media (min-width: 1400px) | @media (max-width: 1399.98px) | 87.5em |
Bootstrap also names an extra small tier for everything under 576px. It has no query of its own because it is the default, unqueried style.
Media query examples for common jobs
Inputs and the query line the tool returns. Each comes wrapped around an .element block for you to fill in.
Tablet only, between md and lg
Approach Range, Minimum width 768, Maximum width 1024, Unit px
@media (min-width: 768px) and (max-width: 1023.98px)
Tablets held sideways
Approach Range, Minimum width 768, Maximum width 1024, Orientation Landscape
@media (min-width: 768px) and (max-width: 1023.98px) and (orientation: landscape)
Small phones in portrait
Approach Desktop first, Breakpoint set Custom, Maximum width 480, Orientation Portrait
@media (max-width: 479.98px) and (orientation: portrait)
One custom mobile-first breakpoint
Approach Mobile first, Breakpoint set Custom, Minimum width 600
@media (min-width: 600px)
A range in em
Approach Range, Minimum width 600, Maximum width 900, Unit em
@media (min-width: 37.5em) and (max-width: 56.2488em)
600 / 16 = 37.5 and (900 - 0.02) / 16 = 56.2488.
Phones up to the md breakpoint
Approach Range, Minimum width 320, Maximum width 768
@media (min-width: 320px) and (max-width: 767.98px)
Why max-width values end in .98
Viewport widths are not always whole pixels. Browser zoom and high-density screens can produce a width such as 767.5px. If one rule covers max-width: 767px and the next starts at min-width: 768px, a 767.5px viewport matches neither, and the element drops back to its base style. The bug is hard to reproduce because it only shows at certain zoom levels or on certain devices.
Writing both as 768 has the opposite problem: at exactly 768px both rules apply at once. Ending the lower range at 767.98px closes the gap without touching 768. Bootstrap uses the same 0.02px subtraction in its own max-width queries.
Mobile-first min-width queries avoid the issue altogether. Their ranges overlap on purpose, and the later rule simply wins, so no viewport can fall between two rules.
Current browsers also accept range syntax, where the same tablet query is written @media (768px <= width < 1024px). The less-than sign excludes 1024 exactly, so no .98 is needed. The tool outputs the older min-width and max-width form, which every browser in use understands.
The dark mode, reduced motion and print queries it adds
Ticking Include preference and print queries appends these three blocks after the width queries.
| Query | Matches when | What the generated block does |
|---|---|---|
| @media (prefers-color-scheme: dark) | The visitor's system or browser is set to a dark theme | Empty .element block for your dark colours |
| @media (prefers-reduced-motion: reduce) | The visitor has asked their system to reduce animation | Sets animation-duration and transition-duration to 0.01ms on every element |
| @media print | The page is printed or saved as a PDF | Hides anything with the class no-print |
The Orientation setting is added to width queries only. These three blocks are always written the same way.
Limits worth knowing before you paste
- Custom produces one breakpoint per run. For a custom set of several widths, generate each one and combine them, in ascending order for min-width or descending order for max-width.
- Range always reads the two width fields, whichever Breakpoint set is selected. The maximum must be larger than the minimum or the tool reports an error. The breakpoint table under the code still lists the selected set, not your range.
- The em option divides by 16. Media queries ignore any font-size you set on html, so 16 is right unless the visitor has changed their browser's default text size, in which case em breakpoints scale with it by design.
- Desktop-first em values carry four decimal places, for example 47.9988em, because 0.02px is subtracted before the division.
- Every block targets a placeholder .element selector. Replace it with your own selectors and rules.
- It writes viewport media queries only. Container queries, prefers-contrast, hover and resolution queries are not generated.
Using Media Query Generator
- 1
Choose an Approach: Mobile first for min-width, Desktop first for max-width, or Range for a query between two widths.
- 2
Choose a Breakpoint set: Tailwind, Bootstrap or Custom.
- 3
For Custom or Range, type the Minimum width and Maximum width in pixels. Mobile first uses the minimum, Desktop first uses the maximum, and Range uses both.
- 4
Set Orientation to Portrait or Landscape if the rule should only apply one way round, and pick px or em as the Unit.
- 5
Leave Include preference and print queries ticked to add dark mode, reduced motion and print blocks, then copy or download the CSS.