Responsive Design: Mobile First, the Viewport Meta Tag and Breakpoints
The foundations of responsive design: the viewport meta tag and why phones need it, mobile-first CSS with min-width queries, choosing breakpoints from the content, intrinsic layouts that need fewer breakpoints, touch-friendly sizing, and testing.
kvi5hnuCode Sprout team member8 min readOn this page
A responsive site adapts to whatever screen it's on, from a phone held upright to a wide desktop monitor, with one set of HTML and CSS. It's not a separate technique so much as a way of using everything in this course: flexible units (Part 4), flexbox and grid (Parts 9 and 10), responsive images (article 53), and the queries in the rest of this part.
The viewport meta tag
Without help, a phone browser pretends to be a desktop: it lays the page out at about 980px wide and shrinks it to fit the screen, so text is tiny and media queries see a desktop width. One line in the <head> turns that off:
<meta name="viewport" content="width=device-width, initial-scale=1">
width=device-widthmakes the layout viewport as wide as the device's screen in CSS pixels, for example 390px on many phones.initial-scale=1starts at 100% zoom.
Every responsive page needs it. Two things not to add:
user-scalable=noormaximum-scale=1stop people zooming, which fails WCAG 1.4.4 (Resize Text) and makes the page unusable for many low-vision users. Some browsers ignore them for that reason.width=600or any fixed width: it brings back the scaling problem on other screen sizes.
Other keys are useful in specific cases: viewport-fit=cover to draw under a phone's rounded corners and notch (with env(safe-area-inset-*) padding, article 57), and interactive-widget to control whether the on-screen keyboard resizes the layout, in mobile browsers.
Mobile first
Mobile-first CSS starts with the styles for the smallest screens, with no media query, and adds layout for larger screens with min-width queries:
/* base: one column, for every screen */
.page { display: grid; gap: 1rem; padding: 1rem; }
/* wider screens: add a sidebar */
@media (width >= 48em) {
.page { grid-template-columns: 15rem 1fr; padding: 2rem; }
}
/* wide screens: more space */
@media (width >= 75em) {
.page { grid-template-columns: 18rem 1fr 18rem; }
}

Only the base rules apply at 360px; each wider viewport adds one query's rules on top, and none of them has to undo anything.
Why start small:
- The small-screen layout is usually the simplest: a single column. Larger screens add columns, which is less CSS than undoing them.
- Phones, which are often slower, get the base styles without applying overrides meant for larger screens.
- It forces content priorities: what matters when there's only room for one column.
The opposite, desktop-first with max-width queries, works too, but tends to produce more overrides. Don't mix both directions randomly in one stylesheet: queries that overlap or leave gaps (max-width: 768px and min-width: 768px both match at exactly 768px) are a common source of bugs. The range syntax, width >= 48em and width < 48em, makes the boundaries explicit (article 76).
Choosing breakpoints
A breakpoint is a width where the layout changes. Don't pick them from a list of devices: there are thousands of screen sizes, and they change every year. Instead:
- Start with the small layout, and widen the browser window slowly.
- When the design starts to look wrong, such as lines of text getting too long (more than about 75 characters) or cards getting too wide, add a breakpoint there.
- Repeat.
Most sites need only two or three. Use em for breakpoint values: in media queries, em and rem are both based on the browser's default font size, not on your html font size. Tested in Chrome: with html { font-size: 10px }, (min-width: 40em) and (min-width: 40rem) both mean 640px. If the user sets a larger default font, em breakpoints move with it, so the layout switches to fewer columns when text is bigger, which is what you want.
Fewer breakpoints: intrinsic layout
Much of what used to need media queries is now built into layout:
| Need | Without a media query |
|---|---|
| as many columns as fit | grid-template-columns: repeat(auto-fill, minmax(min(15rem, 100%), 1fr)) (article 67) |
| a sidebar that wraps under the content | flexbox with flex-wrap and a minimum width (article 65) |
| fluid spacing and text size | clamp() (article 77) |
| a readable line length | max-inline-size: 65ch |
| a component that adapts to its container | container queries (article 78) |
| images that fit | max-inline-size: 100%; block-size: auto |
Media queries are still the right tool for page-level changes: switching the navigation to a menu button, showing a sidebar, changing the overall grid. Components that can appear in different places, like a card in a sidebar or in the main column, are better served by container queries, which respond to the space the component actually has.

The column count comes from the space available, so the same rule works in a phone layout, a sidebar or a wide main column without a single breakpoint.
body { font: 0.8rem system-ui, sans-serif; margin: 1rem; }
.frame { inline-size: var(--w, 18rem); container-type: inline-size; margin-top: 0.5rem; outline: 2px dashed #d8cfc0; }
/* base: one column */
.page { display: grid; gap: 0.4rem; padding: 0.4rem; }
/* the same breakpoint written as a container query, so it works inside this preview */
@container (width >= 19.5rem) {
.page { grid-template-columns: 5rem 1fr; }
header, footer { grid-column: 1 / -1; }
}
.page > * { padding: 0.6rem; border-radius: 6px; background: #f4efe6; border: 1px solid #8a3b12; }
main { min-block-size: 5rem; }
At the narrow width, everything is one column. Widen the frame past the breakpoint and the nav moves beside the main content. On a real page, the same CSS inside @media (width >= 48em) does it for the whole viewport.
Touch and input
Phones are used with fingers, not a mouse:
- Touch targets: make buttons and links at least 24 × 24 CSS pixels, the WCAG 2.2 AA minimum (2.5.8), and preferably about 44 × 44. Padding counts.
- No hover-only features: menus or information that only appear on
:hoverdon't work on touch screens. Use@media (hover: hover)to add hover effects only where hovering is possible (article 76). - Inputs: a text input with a font size below 16px makes iOS Safari zoom in when it's focused; use at least
1rem.
Testing
- Use your browser's device mode (responsive design mode) to try many widths quickly, and drag the width continuously, not just the device presets.
- Test on at least one real phone: touch, the on-screen keyboard, and the dynamic toolbars behave differently from an emulator.
- Zoom to 200% and 400% on a desktop: WCAG 1.4.10 (Reflow) requires content to work at a 320px-wide viewport without horizontal scrolling, which is what 400% zoom of a 1280px window gives.
- Increase the browser's default font size and check that the layout adapts.
What's current
- The viewport meta tag is still required;
interactive-widgetworks in mobile Chrome, Firefox and Safari 27.3. - Media query range syntax (
width >= 48em) works in all browsers (article 76). - Container queries (article 78) are Baseline, and handle component-level responsiveness better than media queries.
- Dynamic viewport units (
dvh, article 25) handle mobile browser toolbars.
Common questions
Why does my page look tiny on a phone? The viewport meta tag is missing, so the phone lays out the page at desktop width and scales it down.
Should I use min-width or max-width queries?
min-width for mobile-first, which is usually simpler. Either works if you're consistent and the ranges don't overlap.
Which breakpoints should I use?
Where your content needs them, found by resizing the browser. Write them in em.
Should I disable zooming on mobile? No. It fails WCAG and blocks users who need to zoom.
Summary
<meta name="viewport" content="width=device-width, initial-scale=1">is required, and must not disable zoom.- Mobile-first: base styles for small screens,
min-widthqueries to add layout. - Choose breakpoints from the content, in
em, which follows the browser's default font size. - Intrinsic layouts (auto-fill grids, wrapping flexbox,
clamp(), container queries) reduce the number of breakpoints. - Design for touch: adequate targets, no hover-only features, inputs at least 16px.
- Test by resizing continuously, on real devices, and at 400% zoom.
Practice questions
Rewrite this desktop-first rule as mobile first.
.nav { display: flex; gap: 2rem; }
@media (max-width: 47.99em) { .nav { display: none; } }
Answer
.nav { display: none; }
@media (width >= 48em) { .nav { display: flex; gap: 2rem; } }
A site has html { font-size: 62.5%; } and a breakpoint at @media (min-width: 60rem). At what viewport width does it apply, with the default browser settings?
Answer
960px. Media queries use the browser's default font size, 16px, not the root element's font size, so 60rem is 60 × 16px.
What's wrong with this viewport tag?
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
Answer
maximum-scale=1 and user-scalable=no prevent zooming, which fails WCAG 1.4.4 and makes the page hard to use for people with low vision. Keep only width=device-width, initial-scale=1.
Name two layouts that used to need media queries but can be built without them.
Answer
Any two of: a card grid with repeat(auto-fill, minmax(min(15rem, 100%), 1fr)); a sidebar that wraps with flexbox; fluid type and spacing with clamp(); components that respond to their container with container queries.
Previous: Table Layout: Table Display, Borders, Sizing and Responsive Tables
Next: Media Queries: Media Types, Range Syntax, and User-Preference Features

More in CSS Course
Quiz: CSS Delicate Details
Twenty-five questions on the edge cases that surprise experienced developers: invalid custom properties, shorthands that reset values, layer order with !important, containing blocks, margin collapsing, specificity of :is() and :where(), intrinsic minimum sizes, and more, each checked in Chrome.
Quiz: CSS Interview Questions
Thirty front-end interview questions: cascade, specificity and layers, box model and margin collapsing, stacking contexts, positioning, flexbox and grid, responsive design, custom properties, performance, accessibility, modern selectors and architecture.
Quiz: CSS Course Final Exam
Thirty questions across the whole CSS course: syntax and error handling, selectors, the cascade and layers, values and units, color, the box model, backgrounds, positioning, flexbox, grid, responsive design, typography, generated content, effects, transforms, motion and architecture.
Quiz: CSS Architecture, Tooling and Debugging (CSS Part 17)
Twenty questions on modular CSS and BEM, layering a stylesheet, design tokens and theming, pattern libraries and safe refactoring, preprocessors and build tools, the at-rules reference, and debugging common CSS problems.
Discussion
Sign in to ask a question or share what you learned.