Responsive web design

Also known as: RWD

On this page 7

Responsive web design (RWD) is the practice of building a single page whose layout, typography and media adapt to the viewport of any device, from a narrow phone to a wide desktop monitor. In CSS, it rests on three pillars: fluid grids sized in relative units, flexible images and media that never overflow their container, and media queries that change rules at chosen widths.

The approach replaced the older habit of maintaining a separate mobile site. One HTML document and one stylesheet serve every device, which keeps content, URLs and search indexing consistent while the presentation reshapes itself to the available space.

How responsive web design adapts a layout

A responsive page adapts by letting the browser compute sizes at render time instead of fixing them in pixels. The starting point is the viewport meta tag, width=device-width, initial-scale=1, which tells mobile browsers to use the real device width rather than a simulated desktop canvas of about 980 pixels. Without it, phones shrink the whole page and every other responsive technique is undermined.

Once the viewport is honest, layout containers use percentages, fractions or flexible boxes, so columns grow and shrink with the screen. Images receive max-width: 100% and height: auto, which keeps them inside their columns. Where proportional scaling stops working, a breakpoint applies new rules, for example turning a three-column grid into a single stack.

The following table summarizes the building blocks and the problem each one solves.

Building blockCSS mechanismProblem it solves
Viewport meta tagwidth=device-widthPhones rendering a zoomed-out desktop page
Fluid grid%, fr, Flexbox, CSS gridFixed-width columns overflowing small screens
Flexible mediamax-width: 100%, srcsetImages wider than their container
Media queries@media (min-width: ...)Layouts that need a structural change
Fluid typographyclamp(), rem, vwText too small on phones or too large on desktops
Core building blocks of a responsive page

Units, breakpoints and fluid sizing

The choice of units decides how gracefully a design scales. Relative units such as rem, em, %, vw and the grid fr unit tie sizes to the root font size, the parent element or the viewport, while absolute pixels stay fixed. Modern practice favors rem for spacing and type because it also respects the reader’s browser font setting, an accessibility requirement under WCAG.

UnitRelative toTypical use
remRoot font size, usually 16 pxFont sizes, spacing, media query values
emFont size of the elementPadding that scales with its own text
%Size of the containing blockColumn widths, fluid images
vw / vh1% of viewport width or heightHero sections, fluid type inside clamp()
frFree space in a grid containerDistributing grid tracks
pxCSS reference pixelBorders, hairlines, fine details
Common CSS units in responsive layouts

Breakpoints should follow the content, not specific device models. A good rule is to widen the browser until the layout looks strained, then add a query at that width. Typical results land somewhere between about 480 and 1,280 pixels, but the exact numbers vary by design. Writing queries in em keeps them consistent when users zoom the text.

Fluid sizing reduces the number of breakpoints. A declaration such as font-size: clamp(1rem, 0.9rem + 0.6vw, 1.5rem) grows smoothly between a minimum and a maximum, so headings and gaps scale continuously instead of jumping at fixed widths.

Mobile-first and desktop-first strategies

Mobile-first writes the base styles for the smallest screen and adds complexity with min-width queries, while desktop-first starts wide and removes features with max-width queries. Mobile-first is the prevailing recommendation because the simplest layout loads without overrides and the stylesheet grows progressively more complex only where space allows.

AspectMobile-firstDesktop-first
Query directionmin-width, adding rulesmax-width, overriding rules
Base stylesheetSingle-column, lightweightMulti-column, heavier
Override volumeLow for small devicesHigh for small devices
Content priorityForces early prioritizationRisks hiding content on phones
Best fitNew projects, content sitesLegacy desktop applications
Comparison of the two authoring strategies

Neither strategy dictates which content appears. A frequent anti-pattern is hiding important information on phones with display: none; mobile users usually need the same content in a different arrangement, not less of it.

Modern CSS tools for responsive layouts

Contemporary CSS makes many layouts intrinsically responsive without any media query. Flexbox wraps items onto new lines with flex-wrap, and CSS grid can fill a row with as many columns as fit using repeat(auto-fit, minmax(16rem, 1fr)). These patterns let the content negotiate its own size.

Container queries extend the idea from the page to the component. Instead of asking how wide the viewport is, a card asks how wide its own container is, so the same component can be compact in a sidebar and expanded in the main column. Media queries remain the right tool for page-level decisions, while container queries suit reusable components in design systems.

  • Responsive images: srcset and sizes let the browser download a file matched to the slot width and pixel density, while the picture element allows art direction.
  • User preference queries: prefers-color-scheme, prefers-reduced-motion and hover adapt the design to settings and input type, not only to width.
  • Logical properties: margin-inline and padding-block keep layouts correct in right-to-left and vertical writing modes.

Limitations and common mistakes

Responsive web design solves layout, but it does not automatically solve performance. A phone on a slow network may still download desktop-sized images, large scripts and unused CSS unless the team adds responsive images, lazy loading and code splitting. Testing only in a resized desktop browser also misses touch targets, real network latency and the behavior of on-screen keyboards.

SymptomLikely causeFix
Horizontal scrolling on phonesFixed widths or long unbroken stringsUse max-width, min-width: 0, overflow-wrap
Tiny text on mobileMissing viewport meta tagAdd width=device-width, initial-scale=1
Blurry or heavy imagesOne image file for all screensProvide srcset with several widths
Taps hitting the wrong linkTouch targets below about 44 pxEnlarge padding on interactive elements
Layout breaks at odd widthsBreakpoints set for device modelsSet breakpoints where content strains
Frequent responsive design errors and their fixes

Another misconception equates responsive design with adaptive design. Adaptive design serves a few fixed layouts, sometimes chosen on the server, whereas responsive design is continuous and fluid between and beyond its breakpoints.

Explained without jargon

Responsive web design means building a website once so that it fits any screen by itself. On a phone, the page stacks into one tidy column. On a laptop, the same page spreads out into several columns with larger pictures.

Think of water poured into different glasses. The water stays the same, but it takes the shape of whatever holds it. A responsive page works the same way: the content stays the same while the layout reshapes itself to the screen in front of the reader.

A typical use case

A regional newspaper runs an older desktop site and a separate mobile site, and editors must publish every article twice. Mobile readers often land on broken links when they share stories, and the two versions drift apart over time.

The development team rebuilds the front end with a mobile-first stylesheet. Articles use a single column below 48 rem, a two-column layout with a sidebar above it, and a three-column grid of story cards on the home page built with repeat(auto-fit, minmax(18rem, 1fr)). Photos receive srcset files at 480, 960 and 1,600 pixels wide.

The result is one URL per article and one publishing workflow. Phones download images roughly sized for their screens, editors stop duplicating work, and shared links open correctly on every device.