Range Syntax for Cleaner Queries
You'll learn how to write media queries that read more like natural language using modern range syntax.
Traditional media queries require you to use min-width and max-width, which can feel backward. You write (min-width: 768px) to mean "768 pixels or wider," which requires mental translation. Modern CSS offers range syntax that lets you write comparisons more intuitively, just like math class.
The Traditional Way vs Range Syntax
Instead of:
@media (min-width: 768px) {
/* Styles for tablets and up */
}
You can now write:
@media (width >= 768px) {
/* Styles for tablets and up */
}
See the difference? width >= 768px reads exactly like what it means: "when width is greater than or equal to 768 pixels."
More Readable Ranges
The real power shines when you need both a minimum and maximum:
Old way:
@media (min-width: 768px) and (max-width: 1199px) {
/* Tablet range */
}
New way:
@media (768px <= width < 1200px) {
/* Tablet range */
}
This reads like a math equation: "when width is between 768px (inclusive) and 1200px (exclusive)."
Works with Other Features
Range syntax works with any numeric media feature you've learned:
@media (height > 600px) { }
@media (aspect-ratio >= 16/9) { }
@media (resolution > 2dppx) { }
Key Takeaway: Range syntax (width >= 768px, 768px <= width < 1200px) makes media queries read like plain English, reducing confusion and making your code more maintainable—especially when defining ranges with both minimum and maximum values.