Skip to content
Back to Concepts
CSS UniverseTrack 7: Responsive ArchitectureMedia Queries & Range Syntax
Responsive Architecture ยท Track 7Core Concept 26

Media Queries & Modern Range Syntax

Ditch confusing min-width inversions. Master the modern mathematical range syntax @media (width >= 768px), query device features like hover: hover, and respect user accessibility preferences.

1. Mental Model: The Highway Traffic Director

Think of a media query as an intelligent traffic officer standing at the entrance to your CSS rules. Before letting the browser execute the styling block, the officer checks the user's passport:

Dimension Check

"Is the viewport at least 768px wide?" (width >= 768px)

Input Capabilities

"Does this device have a real mouse pointer, or a clumsy touch finger?" (hover: hover)

User Health & Preferences

"Has the user requested reduced motion due to motion sickness?" (prefers-reduced-motion)

2. The Modern Syntax Leap: Mathematical Inequality Operators

IntentLegacy Syntax (Confusing)Modern Range Syntax (Clear Math)
Tablet and Above@media (min-width: 768px)@media (width >= 768px)
Mobile Only@media (max-width: 767.98px)@media (width < 768px)
Between Tablet and Laptop@media (min-width: 768px) and (max-width: 1024px)@media (768px <= width <= 1024px)

3. Interactive Studio: Live Breakpoint & Preference Simulator

Simulated Viewport Width820px
320px (Mobile)768px (Tablet)1200px+ (Desktop)
Active Media Query Evaluator
/* Active: @media (640px <= width < 1024px) [Tablet] */
Device Category

Tablet Portrait

Evaluated Viewport: 820px

4. Deep Visualizer: Breakpoint Triggers & Themes

Interactive Lab

Media Queries

Test a breakpoint-driven style change using max-width media queries.

Breakpoint: max-width 480px

Try these

  • Lower the breakpoint to see when the style would kick in.
  • Pair with prefers-reduced-motion or color-scheme queries.
  • Use DevTools device toolbar to simulate devices.
Below 480px, this card would become amber (simulated breakpoint).

Use DevTools device toolbar to test breakpoints; pair with prefers-reduced-motion or color-scheme queries.

CSS
@media (max-width: 480px) {
  .card { background: #fbbf24; }
}
HTML
<div class="card">Below 480px, this card becomes amber.</div>

First-Year Student Traps: Media Queries

  • 1.The Exact Breakpoint Collision Bug: Writing @media (max-width: 768px) and @media (min-width: 768px) means that on a tablet with exactly 768px width, both queries match simultaneously, triggering conflicting cascade battles! The modern range syntax @media (width < 768px) and @media (width >= 768px) eliminates this overlap forever.
  • 2.Assuming Mobile Means No Hover: Modern touchscreen laptops (like Surface Pro or iPad Pro with Magic Keyboard) support both touch AND precision mouse hovers! Never test screen width to guess input capabilities; test @media (hover: hover) directly.
Next Masterclass

Container Queries (@container): Component-Driven Design

Style components based on their parent container's width, not the global browser viewport!

Continue to Concept 27