Layout Beginner

Media query ranges without min-width and max-width

Defining a range of viewport widths required two separate media features: min-width and max-width. Media Queries Level 4 introduces range syntax using standard comparison operators, making ranges possible in a single expression.

βœ“ Modern
3 lines
1@media (600px <= width <= 1200px) {
2  .card { grid-template-columns: 1fr 1fr; }
3}
βœ• Old 3 lines
1@media (min-width: 600px) and (max-width: 1200px) {
2  .card { grid-template-columns: 1fr 1fr; }
3}
Widely available Since 2023 94% global usage

This feature is well established and works across many devices and browser versions. It has been available across browsers since 2023.

104+
63+
16.4+
104+
resize the window to see the active breakpoint
Small
< 600px
Medium
600–1200px
Large
> 1200px
Active: …
@media (600px <= width <= 1200px) β€” one expression
✦

Compound ranges in one expression

A between-range like 600px to 1200px takes one expression instead of two media features joined with and.

⚑

Familiar comparison operators

Uses <, <=, >, >= instead of min-/max- prefixes. The direction reads naturally: 600px <= width means width is at least 600px.

∞

Works for all range features

Range syntax works for width, height, aspect-ratio, resolution, and any other range-type media feature.

Old Approach
min-width + max-width
Two features joined with and
Modern Approach
600px <= width <= 1200px
One expression with comparison operators
Operators
< <= > >=
Standard comparison operators

How it works

The old min-width and max-width media features work but read backwards β€” min-width: 600px means the viewport is at least 600px wide. Defining a range required two features connected with and, which gets verbose for common breakpoint patterns.

Media Queries Level 4 range syntax uses standard comparison operators. (600px <= width <= 1200px) is a compound range in a single expression and reads in the same direction as the intent. Both < (exclusive) and <= (inclusive) are available for precise boundary control.

New CSS drops.

Join 400+ readers who've survived clearfix hacks.

ESC