Define breakpoints once and get min-width, max-width or range media queries that do not overlap, with container query equivalents and variables.
4 breakpoints
Mobile-first: each rule applies from its breakpoint upward.
:root {
--bp-sm: 640px;
--bp-md: 768px;
--bp-lg: 1024px;
--bp-xl: 1280px;
}
/* Custom properties cannot be used in a media query condition — the
query is evaluated before custom properties resolve. These are for
use inside rules; the queries themselves need literal values. *//* sm */
@media (min-width: 40rem) {
}
/* md */
@media (min-width: 48rem) {
}
/* lg */
@media (min-width: 64rem) {
}
/* xl */
@media (min-width: 80rem) {
}CSS Media Query Generator runs entirely on your device — nothing is uploaded.
You’re on the Free plan. Compare plans
A breakpoint set written by hand nearly always overlaps somewhere. `max-width: 768px` and `min-width: 768px` both match at exactly 768px, so both rules apply and whichever comes last in the stylesheet wins — which looks like a one-pixel glitch and gets diagnosed as something else entirely. The usual fix is to offset the max-width side by a fraction of a pixel, which is what this generates.
Fractional offsets exist because viewport widths are not integers. A zoomed page or a fractional device pixel ratio produces a width like 767.5px, which falls in the gap left by `max-width: 767px`. Offsetting by 0.02px — the convention Bootstrap settled on after trying smaller values — is small enough to be invisible and large enough to survive the rounding browsers actually do.
Range syntax is the newer and better way to write the same thing: `@media (768px <= width < 1024px)` says what it means and cannot overlap by construction. It is supported in every current browser, so it is the right default for new work, with the min-width and max-width forms kept for stylesheets that need to go further back.
Container queries are offered beside the media queries because they are usually the better tool and are still underused. A media query asks how big the window is; a container query asks how big the component's own container is. For a card that appears in both a sidebar and a main column, the container is the question that has a useful answer, and the window is not.
To stop two breakpoints matching at the same width. max-width: 768px and min-width: 768px both apply at exactly 768px, so the last rule in the file wins and you get a one-pixel glitch. Offsetting the max side closes the overlap without leaving a gap that a fractional viewport width could land in.
For new work, yes. `(768px <= width < 1024px)` cannot overlap by construction and reads as what it means. It is supported in every current browser; the min-width and max-width forms are here for stylesheets that need older support.
min-width, for mobile-first CSS where the base styles are the small-screen case and each query adds to it. max-width inverts that and tends to produce more overriding, though it is still the right choice when you are retrofitting a desktop-only stylesheet.
Whenever the component, not the page, is what should decide. A card that appears in a narrow sidebar and a wide main column needs to know its own width — the window size tells it nothing useful. A container query needs container-type on the parent to work.
px is the common choice and is what device widths are quoted in. em breakpoints scale with the visitor's default font size, so a layout can switch earlier for someone using larger text, which some teams consider a feature. Mixing the two in one set is the thing to avoid.