Designing for Every Screen, Not Just Yours
Responsive design means a page adapts to whatever device it's viewed on — a phone, a tablet, a laptop, an ultra-wide monitor — instead of being built for one fixed screen size and breaking everywhere else.
- ✓@media queries apply CSS rules conditionally, based on the viewport's width, height, or other features.
- ✓Mobile-first means writing base styles for small screens, then layering on rules for larger ones.
- ✓The viewport meta tag in HTML is required for media queries to work correctly on real mobile devices.
A Prerequisite in the HTML, Not the CSS
Without this tag in the <head>, mobile browsers render the page at desktop width and zoom out — media queries won't behave as expected. It should be on every page from Day 1 onward.
<meta name="viewport" content="width=device-width, initial-scale=1.0">
@media and max-width
A media query wraps a block of CSS rules in a condition. max-width: 600px means "apply this only when the viewport is 600px wide or narrower."
.nav-links { display: flex; } /* applies only at 600px wide or narrower */ @media (max-width: 600px) { .nav-links { display: none; } }
Drag the bottom-right corner of the box below to resize it — the cards rewrap as the container narrows, the same way a real page would respond to a smaller viewport.
↘ drag the bottom-right corner
Which Direction Do You Write Rules In?
Two common approaches exist. Desktop-first starts with full-width styles and narrows down with max-width queries. Mobile-first starts with small-screen styles and expands upward with min-width queries — the more common modern approach.
Base CSS targets small screens; min-width queries add complexity for larger ones.
Base CSS targets large screens; max-width queries simplify the layout for smaller ones.
/* mobile-first: base styles are for small screens */ .cards { display: flex; flex-direction: column; } /* expand to a row once there's enough width */ @media (min-width: 700px) { .cards { flex-direction: row; } }
Where to Set Your max-width Values
There's no official standard, but most projects converge on similar ranges, based on common device widths rather than any single "correct" number.
Don't chase exact device widths — new phones and tablets ship every year. Set breakpoints where your own layout actually starts to look cramped, not at a specific model's screen size.
Common Responsive Mistakes
Breaking Down What You Just Learned
Viewport tagThe meta viewport tag in HTML is required before media queries behave correctly on mobile.
@media syntax@media (max-width: Npx) { } wraps CSS rules that only apply below a given width.
Mobile-firstBase styles target small screens; min-width queries layer on complexity for bigger ones.
BreakpointsCommon ranges cluster around ~480px, ~768px, and ~1024px, but should follow your layout, not a device list.
Rearrange, don't hidePrefer flexible layouts that adapt over display: none hiding real content on small screens.
Try It Yourself
Take the flex or grid page skeleton from Day 24 or 25 and add a media query that stacks the sidebar under the content once the viewport drops below 700px.
Make a Layout Genuinely Responsive
Practicing mobile-first media queries
Create day26.html linked to a stylesheet and build the following on the page.
- Confirm the viewport meta tag is present in the head.
- Write mobile-first base styles: a single-column flex layout with flex-direction: column.
- Add a min-width: 700px media query that switches the layout to flex-direction: row.
- Add a nav bar that collapses its links at max-width: 600px, without deleting them from the HTML.
- Resize the browser window and confirm the layout adapts smoothly at each breakpoint.
Recap
Required in the HTML head for media queries to work correctly on mobile devices.
@media wraps CSS rules that apply only when a condition like max-width is met.
Base styles target small screens first; min-width queries expand the layout upward.
Set based on where your own layout looks cramped, not a specific device's screen size.
Key Takeaways
- The viewport meta tag must be present in the HTML for media queries to behave correctly on mobile.
- @media (max-width: Npx) { } applies CSS rules only when the viewport is at or below that width.
- Mobile-first design writes base styles for small screens and expands with min-width queries.
- Breakpoints should follow where a layout actually breaks down, not a fixed list of device sizes.
- Responsive design rearranges and resizes content — it doesn't hide real content with display: none.