Responsive Web Design: A Practical Guide for Every Screen

cover

Most visitors now arrive on a phone, yet plenty of websites still feel like desktop pages squeezed onto a small screen: tiny text, buttons too close together, tables that scroll sideways and menus that are hard to open. Responsive web design is the set of techniques that lets one site adapt to any screen. The basics have not changed much in a decade, but the tools have become much simpler. This guide covers the essentials, the modern CSS that makes them easy, and the mistakes that still break mobile layouts.

What responsive design actually means

A responsive site uses one set of HTML for every device and lets CSS adjust the layout to the space available. The older alternative, a separate mobile site on an address like m.example.com, doubled the maintenance work and often gave mobile visitors less content. Today the separate mobile site is almost always the wrong choice.

Three ideas sit at the core:

  • Fluid layouts that use percentages, flexible units and modern layout tools instead of fixed pixel widths.
  • Flexible media: images and video that shrink with their container.
  • Breakpoints: points where the layout changes, set with media queries or container queries.

Start with the viewport tag

Without this line in the page's head, phones pretend to be a desktop screen about 980 pixels wide and shrink the whole page to fit:

<meta name="viewport" content="width=device-width, initial-scale=1">

It is the single most common reason a "responsive" site looks tiny on a phone. Do not add maximum-scale=1 or user-scalable=no: blocking zoom makes the site harder to use for people with low vision.

Mobile first

Write the base CSS for the smallest screen, then add rules as the screen gets wider. This keeps the mobile styles simple and avoids overriding desktop rules one by one.

.cards { display: grid; gap: 1rem; }

@media (min-width: 40rem) {
  .cards { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 64rem) {
  .cards { grid-template-columns: repeat(3, 1fr); }
}

Choose breakpoints where your content starts to look wrong, not by specific device sizes. New phones and tablets appear every year; your content stays the same.

Let the layout do the work

Flexbox and Grid handle most responsive behaviour with very few media queries. A grid of cards that fits as many columns as there is room for needs just one line:

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
  gap: 1.5rem;
}

Flexbox with flex-wrap: wrap does the same for rows of buttons, tags or navigation items. If these tools are new to you, start with How to Learn CSS Layout: Flexbox, Grid and Beyond.

Container queries: components that adapt to their space

Media queries respond to the size of the whole screen. Container queries respond to the size of the element's container, which is what you usually care about. A product card can switch from stacked to side-by-side whenever its column is wide enough, whether it sits in a narrow sidebar or a wide main area.

.card-wrap { container-type: inline-size; }

@container (min-width: 30rem) {
  .card { display: grid; grid-template-columns: 10rem 1fr; }
}

All modern browsers support container queries, so they are safe to use for new projects.

Fluid typography and spacing

Instead of setting different font sizes at each breakpoint, let them scale smoothly with clamp():

h1 { font-size: clamp(1.8rem, 1.2rem + 2.5vw, 3.2rem); }
.section { padding-block: clamp(2rem, 5vw, 5rem); }

Keep body text at a comfortable size on phones, around 16 pixels or more, and limit line length on wide screens to roughly 60 to 75 characters with max-width. Long lines are as hard to read as tiny ones.

Responsive images

Add one rule so images never overflow their container:

img, video { max-width: 100%; height: auto; }

Then serve the right file for each screen with srcset and sizes, so a phone does not download a 2,000-pixel desktop image. Use the <picture> element when you need a different crop on small screens, such as a tighter portrait version of a wide hero photo. Image size is also the biggest factor in mobile loading time; the Website Speed Checklist covers formats and compression.

Navigation on small screens

A desktop menu with eight items will not fit on a phone. The common patterns:

  • A menu button that opens the full menu. Label it "Menu" or use a recognisable icon with an accessible name.
  • A short visible menu with only the two or three most important links, plus a button for the rest.
  • A bottom bar for app-like sites where visitors switch between a few sections often.

Whatever the pattern, the menu must work with a keyboard and a screen reader, not only with a tap. Building Website Navigation Menus walks through the HTML and CSS.

Touch-friendly details

  • Tap targets should be at least about 44 by 44 pixels, with space between them.
  • Do not rely on hover to reveal menus, prices or important buttons; touch screens have no hover.
  • Use the right input types in forms (type="email", type="tel") so phones show the right keyboard.
  • Keep forms short and labels visible above the fields.

Common mobile layout bugs

The page scrolls sideways

Something is wider than the screen: a fixed-width element, a long URL, a wide table or an image without max-width. In the browser's developer tools, look for the element that sticks out past the right edge. Add overflow-wrap: anywhere for long words and wrap tables in a container with overflow-x: auto.

Text is tiny on phones

The viewport meta tag is missing, or font sizes are set in fixed pixels that were sized for desktop.

Full-height sections jump on mobile

Mobile browser toolbars change the visible height while you scroll. Use the newer svh, lvh or dvh units instead of vh for sections that should fill the screen.

The layout breaks in landscape or on tablets

Breakpoints were set for a few specific devices. Resize the browser slowly from narrow to wide and fix every point where the content looks wrong.

More layout fixes are collected in Common HTML and CSS Problems and How to Fix Them.

How to test

  1. Use the device toolbar in the browser's developer tools, but do not stop there.
  2. Drag the browser window slowly from very narrow to very wide and watch for breaks.
  3. Test on at least one real phone, ideally a mid-range Android device on mobile data.
  4. Try the site with the browser text size increased, and zoom in to 200 percent.
  5. Run PageSpeed Insights on the mobile setting to check loading speed and layout shift.

A responsive design checklist

  • Viewport meta tag in place, zoom not blocked.
  • Base styles written for small screens first.
  • Layouts built with Grid and Flexbox, not fixed widths.
  • Container queries for components that live in different spaces.
  • Fluid type with clamp() and readable line lengths.
  • Images limited to their container and served with srcset.
  • A mobile menu that works with touch, keyboard and screen readers.
  • Tap targets large enough and no hover-only content.
  • No sideways scrolling at any width.
  • Tested on a real phone.

Over to you: What's the mobile layout bug you keep running into on client sites? Share it in the comments below.

Related reading: How to Learn CSS Layout · Building Website Navigation Menus · What Makes a Good Website?

Comments