What is responsive web design?
Responsive web design means one page that fits any screen, from a phone to a wide monitor. Here's what the viewport meta tag does, how fluid layouts and media queries work, why to start mobile first, and how to test it.

Open a news site on a laptop, and you might see three columns side by side. Open the same address on a phone, and the columns stack into one. Nobody built a second site for phones. The same page rearranged itself to fit the screen.
Responsive web design is a way of building one web page that adapts its layout to any screen, from a small phone to a wide monitor. It rests on three tools: flexible layouts that stretch and shrink, images that never grow wider than their space, and media queries that change the CSS at certain widths. Here's how each one works, with the code.
Why does responsive design matter?
People open the same site on phones, tablets, laptops, and TVs. A page with a fixed width, like 1200px, makes phone users scroll sideways to read each line. On a huge monitor, the same page leaves wide empty gaps.
A responsive page fixes both with one set of HTML and CSS. It also helps people who zoom in to read. Zooming makes the page behave like a narrower screen, so a responsive layout rewraps instead of running off the side. The color, contrast, and motion lesson covers the zoom rules that accessibility standards set.
What does the viewport meta tag do?
The viewport is the part of the browser window that shows the page. Every responsive page starts with this line in its <head>.
<meta name="viewport" content="width=device-width, initial-scale=1" />
Without it, mobile browsers lay the page out at a desktop-like width, often 980px, then shrink the whole thing to fit. The text turns tiny, and your phone styles never run, because the browser reports a wide screen.
The width=device-width part makes the layout as wide as the screen. And initial-scale=1 starts the page at normal zoom. Don't add user-scalable=no or maximum-scale=1. They try to stop people from zooming in, and people with low vision rely on zoom.
How do fluid layouts work?
Think of water. Pour it into a glass or a bowl, and it takes the shape of each one. A fluid layout does the same with the screen it lands on: it sizes things in proportions and limits instead of fixed numbers.
/* Fixed: too wide for a phone */
.page {
width: 1200px;
}
/* Fluid: fills small screens, stops growing on big ones */
.page {
max-width: 75rem;
margin: 0 auto;
padding: 0 1rem;
}
Here max-width means "at most this wide". On a phone, the page fills the screen. On a big monitor, it stops at 75rem and sits in the middle.
Flexbox and grid, the two main CSS layout tools, are flexible by default. This grid needs no breakpoints at all:
.cards {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
gap: 1rem;
}
It fits as many columns as there's room for, each at least 15rem wide, and wraps the rest onto new rows. A phone gets one column, and a laptop gets three or four. Flexbox vs grid explains when to pick each.
What are media queries and breakpoints?
A media query is a block of CSS that only applies when a condition is true. The most common condition is a minimum screen width.
@media (width >= 48rem) {
.sidebar {
display: block;
}
}
The sidebar shows only when the viewport is at least 48rem wide. Older code writes the same test as (min-width: 48rem).
The width where the layout changes is called a breakpoint. Choose breakpoints where your content starts to look squeezed or stretched, not at the size of a particular phone. New phones come out all the time, but your content stays the same. Write breakpoints in rem or em rather than px, so they work with the reader's text size. px vs em vs rem explains why.
What does mobile first mean?
Mobile first means writing the CSS for the smallest screen first. Then you add media queries that add columns as the screen gets wider:
/* Phones: one column */
.cards {
display: grid;
gap: 1rem;
}
/* Tablets and up: two columns */
@media (width >= 40rem) {
.cards {
grid-template-columns: 1fr 1fr;
}
}
/* Laptops and up: three columns */
@media (width >= 64rem) {
.cards {
grid-template-columns: 1fr 1fr 1fr;
}
}
The phone layout needs no media query, and each query only adds what changes. A single column is also the simplest layout, so starting there keeps the base CSS small.

How do you make images responsive?
Add this rule to your CSS.
img {
max-width: 100%;
height: auto;
}
The max-width: 100% rule lets an image shrink with its column, but never grow past its real size, where it would look blurry. The height: auto part keeps its shape as the width changes.
That fixes the layout, but a phone still downloads the same big file as a desktop. Sending smaller files to smaller screens is a job for srcset, sizes, and the <picture> element. The responsive images lesson covers them step by step. Also give every image width and height attributes, so the page doesn't jump while it loads. Why images need width and height explains how that works.
What about text size?
Set font sizes in rem, so text follows the size the reader picked in their browser. For headings that grow a little on wide screens, mix in a viewport unit, where 1vw is 1% of the viewport's width:
h1 {
font-size: calc(1.5rem + 2vw);
}
Don't size text in vw alone. Zooming doesn't make that text bigger, which shuts out readers who need it larger.
How do you test a responsive website?
- Resize your browser window. Drag it narrow and wide. Look for sideways scrolling, squeezed text, and parts that overlap.
- Use device mode in Chrome DevTools. Open DevTools and click Toggle device toolbar, or press Cmd+Shift+M on a Mac (Ctrl+Shift+M on Windows and Linux). Pick a phone from the Dimensions list, or choose Responsive and drag the edges.
- Show your breakpoints. In device mode, open More options and choose Show media queries. Your breakpoints appear as bars above the page, and you can click them.
- Try Firefox too. Its Responsive Design Mode opens with Ctrl+Shift+M, or Cmd+Option+M on a Mac.
- Test on a real phone. Device mode only approximates one.
Device mode can also slow down the CPU and network to feel more like a phone. Low-end devices explains why that matters. If DevTools is new to you, start with debugging in the browser.
What are common responsive design mistakes?
- Leaving out the viewport tag. Without it, phones show a shrunken desktop layout, and your narrow-screen styles never kick in.
- Fixed widths on big boxes. A
width: 1200pxcontainer forces sideways scrolling. Usemax-widthinstead. - Turning off zoom. Setting
user-scalable=notries to block zoom, and some readers can't read the page without it. - Breakpoints for one device. Pick widths where your content breaks, not where a phone model happens to sit.
- Actions that only appear on hover. Phones have no mouse pointer to hover with, so make sure a tap can reach everything.
Where should you go next?
Responsive design builds on layout, so learn flexbox and grid and how to center a div next. The CSS box model shows how padding and borders change an element's size. If you use Tailwind, its prefixes like md: are mobile-first media queries, and Tailwind CSS vs CSS shows them side by side with plain CSS.
To react to screen size in JavaScript, try building a useMediaQuery hook in React. And when your layout works everywhere, the web performance course shows how to make it load fast on phones too.


