Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Build responsive pages by starting with semantic HTML and a fluid layout, then add media queries only when the content needs a different arrangement. Use flexible Grid or Flexbox tracks, relative sizing, readable text, and the viewport declaration; test around the widths where your content changes, not against a list of phone models. MDN Web Docs defines responsive design as “a site or application design that responds to the environment in which it is viewed.”

What responsive design means

Responsive design is an approach, not a framework or a set of device templates. A responsive page adapts to viewport size, resolution, zoom, orientation, input capabilities, print, and user preferences. The same document should remain understandable when a user narrows a browser, enlarges text, rotates a device, or enables reduced motion.

HTML already provides useful responsiveness: text wraps, blocks stack, and content reflows in source order. CSS should avoid forcing that behavior into a fixed canvas. A layout is successful when content remains readable and controls remain usable, even if its visual arrangement changes.

Start with semantic HTML and a flexible base

Write meaningful structure before styling. Headings should describe sections, navigation should use <nav>, repeated content can use lists, and actions should be buttons or links rather than clickable generic containers. Source order is the fallback layout for narrow screens, keyboard users, screen readers, and CSS-disabled browsing.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Responsive article</title>
    <link rel="stylesheet" href="styles.css">
  </head>
  <body>
    <header class="site-header">...</header>
    <main>
      <article>
        <h1>A useful heading</h1>
        <p>Content remains in a logical reading order.</p>
      </article>
      <aside>Related information</aside>
    </main>
  </body>
</html>

The viewport element matters on mobile browsers. Without it, a browser may lay the page out on a wide virtual viewport and scale it down, so narrow-screen media queries do not behave as intended. Keep the declaration exactly in the document head.

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, sans-serif;
  line-height: 1.5;
  color: #202124;
  background: #fff;
}

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

main {
  width: min(100% - 2rem, 70rem);
  margin-inline: auto;
  padding-block: 2rem;
}

p { max-width: 70ch; }

button, input, select, textarea { font: inherit; }

box-sizing: border-box makes declared widths include padding and borders. The min() expression provides side gutters while capping line length. A maximum text width helps people track long lines; adjust it for your content and language.

Let Flexbox and Grid respond before adding breakpoints

Flexbox for one-dimensional arrangements

Flexbox is useful when items primarily flow in a row or a column. Allow wrapping instead of assigning every item a fixed width.

.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
}

.site-header nav {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem 1rem;
}

.card-list {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.card-list > * {
  flex: 1 1 16rem;
}

Each card can grow, shrink, and wrap when the available space changes. This often eliminates a breakpoint entirely.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Grid for two-dimensional layouts

Grid handles rows and columns while preserving a predictable source order.

.dashboard {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr));
  gap: 1rem;
}

.page-layout {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(14rem, 1fr);
  gap: 2rem;
}

auto-fit and minmax() let the browser choose how many columns fit. The minmax(0, 2fr) pattern prevents long content from forcing horizontal overflow. If the layout still becomes cramped, introduce a content-led media query.

Use media queries when the content needs a change

A breakpoint is a point at which presentation changes; it is not a phone or tablet category. Resize the design and note where navigation, headings, forms, or columns stop working. Put the query near that failure and prefer relative units such as rem so zoom and user font settings are respected.

@media (max-width: 48rem) {
  .page-layout { grid-template-columns: 1fr; }
  .site-header { align-items: flex-start; }
}

@media (min-width: 70rem) {
  main { padding-inline: 0; }
}

Use the fewest breakpoints that solve real problems. A component can also respond to its own available space with Grid or Flexbox, avoiding a page-wide breakpoint. When a modern component query is appropriate, check browser support for your target audience before relying on it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Queries for conditions besides width

Media queries can address orientation, print, interaction and preferences.

@media (orientation: landscape) {
  .hero { min-height: 60vh; }
}

@media print {
  nav, .no-print { display: none; }
  a { color: #000; text-decoration: underline; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}

@media (prefers-reduced-data: reduce) {
  .decorative-video { display: none; }
}

Only change presentation when the condition warrants it. Do not hide essential information merely because a viewport is narrow.

Make text, controls and media usable at every size

  • Use relative units for spacing and type where possible. Do not disable browser zoom.
  • Keep body text readable and allow it to wrap; avoid fixed-height boxes that clip enlarged text.
  • Give controls comfortable targets, visible focus styles, labels, and sufficient contrast.
  • Preserve a logical DOM order. Visual reordering with order or grid placement can make keyboard navigation confusing when it differs from reading order.
  • Do not convey meaning by color alone. Check focus, hover, error and disabled states at high zoom and with forced colors where applicable.
  • Provide useful alternatives for images and ensure tables, forms and landmarks remain navigable when columns stack.

Responsive design can improve accessibility for people who zoom or use small viewports, but only if the underlying source order and interaction model remain sound. W3C WAI and web.dev provide additional accessibility and responsive-design guidance.

Test the layout systematically

  1. Load the page at a wide viewport, then drag the browser edge slowly narrower. Record the first point where text, navigation, cards or forms become cramped.
  2. Add or adjust a content-led breakpoint at that point. Check a few pixels above and below it for wrapping and overflow.
  3. Use browser responsive-design tools to simulate viewport widths, orientation and device pixel ratio. Simulation checks CSS behavior; it is not a substitute for testing on physical hardware.
  4. Test zoom, including enlarged text, keyboard-only navigation, reduced motion, print preview and a slow connection.
  5. Check real images, long URLs, translated strings, empty states and validation errors. These often expose fixed widths that ordinary content hides.
  6. Inspect for horizontal scrolling with the browser’s layout tools and by tabbing through every control.

Keep a small test matrix of representative narrow, intermediate and wide widths plus the exact widths surrounding each breakpoint. You are testing behavior, not whether a page matches a named device.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Common responsive-layout failures and fixes

Unexpected horizontal scrolling

Typical causes are a fixed-width child, an unbroken URL, a grid track with an implicit minimum, or media that lacks a maximum width. Use minmax(0, 1fr), overflow-wrap: anywhere for appropriate text, and max-width: 100% on replaced elements. Find the offending element in the browser’s layout inspector rather than hiding overflow on the body.

Mobile media queries never apply

Confirm the viewport declaration is present and that the stylesheet loaded. Check selector specificity and whether a later rule overrides the query. Test the actual computed styles at the target width.

Cards become unreadably narrow

Replace fixed column counts with auto-fit/minmax(), or add a breakpoint where the card’s content no longer fits. Let cards stack before reducing type to an unusable size.

Visual order conflicts with keyboard order

Remove unnecessary order or grid placement changes and arrange the HTML in the intended reading sequence. If a visual change is essential, verify it with keyboard and assistive-technology users.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Images or embeds overflow

Apply responsive dimensions to images, SVGs, videos and iframes; check intrinsic widths and captions. For art direction, use responsive image markup rather than stretching a single oversized asset.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup: capture responsive states with ScreenshotNeo

When you need repeatable screenshots of several viewport configurations, ScreenshotNeo provides a website screenshot API and MCP server. Its clean-shot process accepts cookie banners and removes more than 60 known consent platforms, newsletter popups and chat widgets before capture; each of those steps can be disabled. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads and cache hits cost nothing, and response headers report the page verdict and whether the shot was billed.

Use the API to capture a page after your local responsive checks. Full documentation, including viewport and device options, is at https://screenshotneo.com/docs/.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

For responsive QA, choose a viewport or device preset, request full-page capture when needed, and use custom CSS or JavaScript to set a test state. ScreenshotNeo also supports element capture by CSS selector, dark mode, retina scale, lazy-image loading, waits for a selector, delay or network idle, hidden selectors, blocked resources, custom headers and cookies, timezone and geolocation, image resizing, transparent backgrounds, caching with a chosen TTL, signed links, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, a usage API and an OpenAPI specification. PDF output includes paper size, margins, landscape mode and page ranges.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

An MCP server exposes take_screenshot, get_page_info and capture_pdf to Claude, Cursor and other MCP clients, so an AI agent can inspect responsive states without you wiring a browser runner. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account to begin.

FAQ

Do I need a media query for every component?

No. Flexbox and Grid can adapt many components continuously. Add a query only when content or a condition requires a structural or presentation change.

Should breakpoints match popular device widths?

No. Choose widths from the point your own content becomes cramped, using relative units where practical.

Is browser responsive mode the same as testing a phone?

No. It is valuable viewport simulation, but physical devices can reveal input, font-rendering, performance and browser differences.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Why is the viewport meta element important?

It tells mobile browsers to use the device width for layout. Without it, a wide virtual viewport can prevent narrow-screen queries from applying as expected.

Frequently Asked Questions

Can responsive CSS support print and reduced-motion preferences?

Yes. Media queries can target print and user preferences such as reduced motion or reduced data, allowing a presentation suited to that environment.

What should I check first when a page overflows horizontally?

Inspect fixed-width children, long unbroken strings, grid tracks without a zero minimum, and media lacking max-width: 100%. Correct the offending element instead of hiding overflow globally.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.