CSS Media Query Generator
Breakpoint scaffolds for Tailwind, Bootstrap or your own.
/* Mobile-first: styles cascade upward. */
@media (min-width: 640px) {
/* sm and up */
}
@media (min-width: 768px) {
/* md and up */
}
@media (min-width: 1024px) {
/* lg and up */
}
@media (min-width: 1280px) {
/* xl and up */
}
@media (min-width: 1536px) {
/* 2xl and up */
}
Breakpoints worth keeping
A breakpoint scaffold is thirty seconds of typing you should never do twice — and two details that are easy to get wrong: the fractional-pixel gap between adjacent queries, and whether your units respect the reader's font-size setting. Both are handled here.
How to use it
-
Pick a breakpoint set
Start from Tailwind, Bootstrap or MUI defaults so your CSS lines up with the framework you are already using, or build your own.
-
Choose a strategy
Mobile-first min-width queries, desktop-first max-width, or exclusive ranges where exactly one query matches at any width.
-
Choose px or em
em queries respond to the reader's browser font-size setting. px queries do not.
-
Copy the scaffold
You get the query blocks with the breakpoint names as comments, ready to fill in.
The 0.02px detail
Pairing max-width: 767px with min-width: 768px leaves a hole:
viewports report fractional widths on high-density screens, and a window at 767.5px matches
neither rule. Subtracting a hundredth of a pixel from the upper bound closes it. The
desktop-first and range modes above do this automatically.
Prefer fewer breakpoints
Every breakpoint is a layout you have committed to designing and testing. Modern CSS removes
the need for most of them: repeat(auto-fill, minmax(260px, 1fr)) reflows without
any, and clamp() scales type and spacing continuously. Reach for a breakpoint
when the layout genuinely needs to become a different shape — not when something just needs
to be a bit bigger.
Container queries
Media queries ask how wide the window is. Container queries ask how much room the component actually has, which is the better question for anything reusable. A card that has to work in a 1000px main column and a 280px sidebar cannot be styled correctly from the viewport width alone.
Frequently asked questions
Should I use min-width or max-width media queries?
Why do breakpoints use 767.98px instead of 767px?
max-width: 767px and min-width: 768px, a window at 767.5px matches neither rule and your styles vanish. Subtracting 0.02 closes the gap — it is why Bootstrap does the same.What is the difference between px and em in media queries?
em query respects the reader's browser font-size setting; a px query ignores it. The em is measured against the browser default rather than your CSS, so for someone who has raised their default text size the query fires at a proportionally larger viewport — keeping the layout matched to the text.When should I use container queries instead of media queries?
How many breakpoints do I need?
minmax(), auto-fill and clamp() remove the need for most of them.