In this lesson you will
- Add the viewport meta tag and explain what breaks without it
- Make images and boxes flexible so nothing scrolls sideways at 320 pixels
- Write mobile-first media queries and pick breakpoints from the content
- Scale headings with clamp() and respect user preferences such as reduced motion
The viewport meta tag
Phone browsers were built at a time when most sites were designed only for desktops. To show those sites at all, a phone pretends its screen is about 980 pixels wide and then zooms the whole page out, so text becomes tiny. Your media queries never fire, because the browser thinks it is a wide screen. One line in the head switches this off: <meta name="viewport" content="width=device-width, initial-scale=1"> tells the browser to use the device’s real width at normal zoom.
Put it on every page, right after the charset line. Do not add user-scalable=no or maximum-scale=1 to stop people zooming: people with low vision rely on pinch zoom, and blocking it can fail WCAG success criterion 1.4.4, Resize Text. The sizes media queries talk about are CSS pixels, not the physical pixels of the screen, so a phone with a very sharp display still reports a width of around 360 to 430 CSS pixels.
Sign in free to read the full lesson
You are reading the free preview. Create a free account (it takes one minute, no password) to unlock the rest of this lesson and track your progress.
Unlocks after sign-in:
- 3 more sections with live code examples
- Common mistakes to avoid
- Hands-on coding exercise with automatic checks
- Practice quiz and the graded lesson test
Free forever. No card, no paywall.
Questions people ask
What is responsive web design?
It is building one page that adapts its layout to the screen it is viewed on, from a small phone to a wide monitor, using flexible layouts, flexible images and media queries. It replaced the old approach of a separate mobile site at an address such as m.example.com.
What breakpoints should I use for mobile, tablet and desktop?
There is no official list. Many sites end up with breakpoints near 40rem (640px) and 64rem (1024px), but the right ones are where your layout needs them. Start with the phone layout, widen the window, and add a query only where something breaks.
Should I use min-width or max-width media queries?
Prefer min-width with a mobile-first stylesheet: the base CSS is the simple phone layout and each query adds to it. max-width queries are fine for small fixes, but a stylesheet built mostly on them tends to undo desktop styles for phones, which means more code.
Is it OK to stop users zooming with the viewport tag?
No. user-scalable=no and maximum-scale=1 block pinch zoom, which people with low vision depend on, and accessibility checkers based on WCAG report it as a failure. Fix the layout so it does not need blocking instead.
What is the difference between media queries and container queries?
Media queries test the whole browser window or device, such as its width or dark mode setting. Container queries test the size of a parent element, so one component can change its own layout wherever it is placed. Both work in all current major browsers.
Sources
Facts in this lesson were checked against these official pages on 29 October 2026.
- MDN: Responsive web design
- MDN: Media query fundamentals
- MDN: The viewport meta tag
- MDN: clamp()
- MDN: Container queries
- W3C: Media Queries Level 4
- W3C WAI: Understanding WCAG 2.2 Reflow (1.4.10)
Code examples stay in English and run in a sandbox on your device. If you spot a mistake, tell us through the contact page.