Full answer
A media query applies a block of CSS only when a condition is true, such as the viewport being at least 600px wide. Responsive design means the same HTML adapts to many screen sizes using fluid widths, flexible images and media queries.
A page needs the viewport meta tag to work properly on phones: <meta name="viewport" content="width=device-width, initial-scale=1">. Without it, many mobile browsers pretend to be about 980px wide and shrink the page.
Mobile-first means the base CSS is written for the smallest screen. You then add min-width queries to enlarge the layout. Phones download simple CSS, and each breakpoint adds only what is new. Choose breakpoints where your content starts to look bad, not at fixed device sizes.
At a 400px wide window the cards are in one column, at 700px in two columns and at 1000px in three. Beyond width, media features cover user preferences: colour scheme, reduced motion, contrast, pointer type ((hover: hover)), orientation and print.
A related tool is the container query, which checks the size of a parent box instead of the viewport. It suits components that appear in different places.
<style>
body { margin: 0; font-family: sans-serif; }
.grid { display: grid; gap: 1rem; padding: 1rem; grid-template-columns: 1fr; }
.card { background: #eef; padding: 1rem; }
@media (min-width: 600px) { .grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 900px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (prefers-color-scheme: dark) { body { background: #111; color: #eee; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media print { .grid { display: block; } }
</style>
<div class="grid" id="g"><div class="card">1</div><div class="card">2</div><div class="card">3</div></div>Run in Chrome 156 (headless) as a page; the snippet is wrapped in a minimal HTML document with doctype, charset and viewport meta tag. Two full runs gave identical results, and the measured values in the answer come from them.
Key points
- The viewport meta tag is needed for width queries to work on phones.
- Mobile-first uses min-width queries that add layout as space grows.
- Breakpoints should follow content, not device models.
- prefers-color-scheme and prefers-reduced-motion respond to user settings.
- Container queries handle component-level decisions.
Common mistakes
- forgetting the viewport meta tag and wondering why media queries do not fire on a phone.
- tying breakpoints to specific devices (iPhone width, iPad width). Devices change every year, so base them on content.
Follow-ups
- how do you test responsive layouts?
- How do container queries differ from media queries?
- Why avoid mixing min-width and max-width queries in one stylesheet?
Tips
- Write base styles for mobile and use min-width. Mixing min-width and max-width in the same file leads to overlapping ranges that are hard to follow.
- Say that you set breakpoints where the content breaks, and show one example with two breakpoints.
- Mention user-preference queries; they separate junior answers from stronger ones.