ScreenshotNeo

BlogHow-to

How to Test Responsive Layouts with Screenshots at Multiple Viewport Sizes

Test responsive layouts at meaningful viewport widths with Chrome DevTools and Playwright, then compare stable screenshots to catch regressions.

By the ScreenshotNeo team4 October 20267 min read

To test responsive layouts with screenshots, capture the same page at explicit viewport widths around your CSS breakpoints, then compare those images with an approved baseline. Use Chrome DevTools for quick manual inspection; use Playwright Test to repeat the captures and detect visual regressions in CI. Keep the browser, environment, page state, and capture region consistent. Emulated viewports are useful for checking CSS layout, but they do not prove behavior on real mobile hardware.

1. Choose viewport sizes that exercise your breakpoints

Start with the breakpoints in your CSS and the widths at which your layout changes. Include widths just below and just above each important breakpoint: a layout can work at the named breakpoint and still fail at the transition. Record the viewport width and height, rather than relying only on device names.

Chrome DevTools Device Mode offers convenient preset widths of 320, 375, 425, 768, 1024, 1440, and 2560 pixels, as well as custom dimensions. Treat these as presets, not a universal test standard. Add project-specific widths based on your layout and audience.

Case What it can reveal
Just below a breakpoint Overflow, cramped columns, or a navigation pattern that changes too late.
At the breakpoint Whether the intended layout switch occurs at the expected width.
Just above a breakpoint Gaps, overlap, or an early switch to the wider layout.
Narrow, medium, and wide representative widths Problems that appear within a layout mode, even away from a transition.

Choose heights deliberately too. A short viewport can expose clipped menus or sticky headers; a taller one can show more content in a viewport capture. Keep height fixed between runs if you intend to compare screenshots.

2. Capture responsive layouts manually in Chrome DevTools

  1. Open the page in Chrome and open DevTools.
  2. Turn on Device Mode. Enter a width and height, or drag the responsive viewport. Repeat for the widths in your test matrix.
  3. Wait for the page to settle. Check the layout, navigation, text wrapping, images, and any horizontal overflow.
  4. For the visible browser viewport, choose More options > Capture screenshot. To include content outside the current viewport, choose Capture a full size screenshot.
  5. Name or organize captures so each records the page, viewport, and state. Keep the same capture region and page state when you repeat the check.

Manual captures are useful for exploration: resize around a problem area, inspect the transition, and save evidence. They do not automatically detect a change from a previous image, so use a visual baseline workflow when you need repeatable regression checks.

3. Automate viewport screenshots and comparisons with Playwright

Playwright can set explicit viewport dimensions in a browser context or use device descriptors that model settings such as viewport, screen size, user agent, and touch capability. For responsive CSS coverage, explicit dimensions make the tested layout width clear. Use a device descriptor when you specifically want to exercise a target device profile, and document what it emulates.

The following example uses Playwright Test. Install Playwright and its browser for your project, save this as tests/responsive.spec.ts, and replace the example URL and viewport matrix. On the first run, Playwright creates reference screenshots; review and commit those references. Later runs compare against them.

import { test, expect } from '@playwright/test';

const viewports = [
  { name: 'mobile-narrow', width: 320, height: 780 },
  { name: 'mobile-wide', width: 425, height: 900 },
  { name: 'tablet', width: 768, height: 1024 },
  { name: 'desktop', width: 1440, height: 900 },
];

test('responsive page matches its viewport baselines', async ({ page }) => {
  for (const viewport of viewports) {
    await page.setViewportSize({ width: viewport.width, height: viewport.height });
    await page.goto('https://example.com', { waitUntil: 'networkidle' });
    await expect(page).toHaveScreenshot(`responsive-${viewport.name}.png`);
  }
});

Run the test with your project’s Playwright Test command, for example npx playwright test. The first run generates snapshots; inspect them before accepting them as references. After an intentional design change, update references with npx playwright test --update-snapshots and review the diff before committing.

Playwright’s screenshot assertion waits for two consecutive screenshots to match before comparing. It disables animations by default. You can configure assertion options such as fullPage to capture the full scrollable page, mask to cover volatile elements, a custom style to hide unpredictable content, and threshold to tolerate small pixel or color differences. Use a threshold deliberately; a permissive value can conceal a real layout problem. Screenshot comparison is provided by the Playwright Test runner.

Use a viewport screenshot for above-the-fold layout checks. Set fullPage: true when the question concerns the whole scrollable document. Do not mix viewport and full-page snapshots under the same baseline name: their dimensions and purpose differ.

4. Keep screenshot runs stable and useful

  • Fix the environment. Keep the host OS, browser version, browser settings, and headless mode consistent between baseline creation and comparison. Rendering can vary with those factors, hardware, and power source.
  • Fix page state. Use deterministic test data and a consistent login, consent, and loading state. Wait for the content relevant to the capture instead of taking a screenshot while it is still changing.
  • Control volatile content. Mask timestamps, rotating promotions, or other changing regions; use a stylesheet to hide content that should not participate in the comparison.
  • Review changes. Treat a visual diff as evidence to inspect, not an automatic verdict. Commit and review snapshot files alongside the test that explains their intended coverage.
  • Keep coverage focused. Cover meaningful breakpoints and transitions rather than multiplying near-identical captures without a layout reason.

5. Know what viewport emulation can and cannot show

Chrome describes Device Mode as an approximation of how a page looks and performs on a mobile device; it does not run your code on an actual phone. Playwright device descriptors likewise emulate browser settings. These tools are appropriate for repeatable CSS layout checks, but do not establish that hardware-dependent behavior or every platform detail matches a physical device.

When a bug depends on touch behavior, device hardware, or platform-specific rendering, add a check on a real phone or tablet. Use the emulated screenshot matrix for broad, repeatable layout coverage, and treat real-device checks as additional evidence where the risk calls for it.

6. Troubleshooting screenshot differences

Symptom Likely cause Fix
Text or spacing differs on every run Browser or host environment differs from the baseline, or content has not settled. Use the same browser and environment; wait for the relevant content and stabilize test data.
Only a timestamp, avatar, or promotion changes Volatile page content is included in the image. Mask the element or hide it with the screenshot assertion’s custom stylesheet.
Snapshot has the wrong dimensions Viewport size changed, or a full-page capture was mixed with a viewport capture. Set the intended width and height before navigation and keep capture mode consistent.
Screenshot is blank or missing late-loaded content The capture happened before the content or images were ready. Wait for a meaningful selector or other page-specific readiness condition before capturing.
A baseline update hides an unexpected regression Snapshots were updated without reviewing the visual diff. Review generated images and diffs before accepting and committing snapshot updates.
Emulated layout passes but a real phone behaves differently Emulation does not reproduce all hardware and platform behavior. Reproduce the issue on the target physical device and add a device check for that behavior.
Small rendering noise causes frequent failures Rendering varies slightly across environments or content is unstable. Stabilize the environment and content first; apply a carefully chosen threshold only for expected differences.

7. Performance, reliability, and cost

More viewport cases mean more browser navigations and image comparisons. Keep the matrix tied to actual breakpoints and high-value layout modes; use a small representative set on every change and broader coverage when appropriate for your release process. Full-page images can be larger and compare more content than viewport captures, so use them only when the whole page is in scope.

Visual regression is reliable when the reference and comparison runs control browser, host, page state, dimensions, and capture region. It is not a substitute for functional assertions: a screenshot can show a broken layout, but a test should separately assert that important controls and navigation work. Screenshot capture itself can be done with free Chrome DevTools or Playwright; the main costs are CI compute, browser execution time, and maintaining reviewed baselines.

Or skip the browser setup

For a one-call screenshot at a chosen viewport, use ScreenshotNeo’s API. It accepts width and height parameters along with the URL; see the docs for the supported parameter names and options. This runnable cURL example captures a page at 375 by 812 pixels:

curl -G "https://api.screenshotneo.com/v1/shot" \
  -d access_key=YOUR_API_KEY \
  --data-urlencode url=https://stripe.com \
  -d width=375 \
  -d height=812 \
  -o mobile.webp

ScreenshotNeo accepts cookie and consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers report the page verdict and billing status. Its MCP server lets AI agents use take_screenshot, get_page_info, and capture_pdf. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots. Every feature is on every plan. See ScreenshotNeo for the product details and the API documentation for all options.

Create a free ScreenshotNeo account for 1,000 screenshots a month with no card.

FAQ

Should I test every possible viewport width?

No. Select widths that cover your layout modes and the transitions around the breakpoints where the design changes.

Should a responsive test use a device name or exact dimensions?

Use exact dimensions to isolate responsive CSS. Use a device descriptor when the device profile itself is part of the test, and state what it emulates.

Do screenshots prove a page works on a phone?

No. Emulated screenshots are useful layout evidence. Check a physical device when hardware or platform behavior matters.

Can I compare screenshots with plain Playwright?

Use Playwright Test’s toHaveScreenshot() assertion for baseline comparisons; screenshot comparisons are part of the test runner workflow.