October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

How to Configure Chromatic Viewports for Responsive Screenshots

Use Chromatic Modes to give selected Storybook stories distinct responsive viewport snapshots, with control over dimensions, cropping, and scope.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For Storybook, configure responsive screenshots with Chromatic’s Modes API: define viewport sizes in .storybook/modes.ts, then attach the modes to the stories or components whose responsive behavior you want to check. Each mode creates its own snapshot and approval baseline. Use Storybook viewport presets if your project already defines them.

Configure responsive viewports with Storybook Modes

Define named modes with explicit pixel dimensions, then apply only the modes relevant to each story or component. This keeps responsive coverage focused instead of creating extra snapshots for every story. See Chromatic’s Modes viewport guide and Story Modes documentation.

As an Amazon Associate I earn from qualifying purchases.

1. Define the viewport modes

// .storybook/modes.ts
export const allModes = {
  mobile: { viewport: { width: 375, height: 812 } },
  desktop: { viewport: { width: 1280, height: 900 } },
} as const;

These are example dimensions, not required device sizes. Chromatic accepts whole-number dimensions and integer strings with an optional px suffix. Its documented range is 200–2560 pixels for width or height.

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

2. Apply modes to the stories that need them

import { allModes } from '../.storybook/modes';

const meta = {
  component: Example,
  parameters: {
    chromatic: {
      modes: {
        mobile: allModes.mobile,
        desktop: allModes.desktop,
      },
    },
  },
};
export default meta;

Attach the chromatic.modes parameter at story or component scope; project-level modes are also available. Because each applied mode produces a separate snapshot with its own baseline and approval, scope them to stories where layout changes matter. Chromatic says global assignment is not recommended in most cases.

Reuse existing Storybook viewport presets

If your project already names viewport presets, define them in .storybook/preview.ts and reference their keys from the modes file. Storybook’s viewport options use dimensions in styles; Chromatic’s mode then selects the preset rather than repeating its dimensions.

// .storybook/preview.ts
export const parameters = {
  viewport: {
    options: {
      mobile: {
        name: 'Mobile',
        styles: { width: '375px', height: '812px' },
      },
      desktop: {
        name: 'Desktop',
        styles: { width: '1280px', height: '900px' },
      },
    },
  },
};
// .storybook/modes.ts
export const allModes = {
  mobile: { viewport: 'mobile' },
  desktop: { viewport: 'desktop' },
} as const;

Chromatic Modes do not accept every unit available to Storybook’s viewport feature: dimensions must be whole numbers or integer strings ending in px. Values such as rem and calc() are not supported as mode dimensions. Details and examples are in Chromatic’s viewport configuration guide.

Understand viewport size, capture height, and cropping

Chromatic documents a default viewport of 1200 × 900 pixels when no viewport is set. A width-only mode trims the capture to content height; a height-only mode uses a default width of 1200 pixels and trims to content width. A snapshot may contain at most 25,000,000 pixels.

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

Setting a viewport sizes the browser, but does not by itself clip a screenshot to the viewport’s height. By default, Chromatic captures the rendered UI’s full height. To clip it to the configured viewport height, set parameters.chromatic.cropToViewport: true. A root taller than the viewport can be clipped; a shorter root is captured only to its intrinsic height.

For unusually large captures, Chromatic documents a Safari and Firefox image-dimension limit of 32,767 pixels. At device pixel ratio 2.0, that limit is reached at half the CSS-pixel dimension; Chromatic says it automatically retries those captures at DPR 1.0. Consult the cross-runner viewport documentation when planning oversized snapshots.

Choose the right configuration scope and precedence

  • Story or component modes: Best when only selected responsive layouts need review. Each configured mode creates an additional snapshot and baseline.
  • Project-level modes: Available, but applying every viewport globally can multiply snapshots unnecessarily.
  • Storybook viewport globals: These can control the Storybook canvas and may be respected by Chromatic. A story-level chromatic.viewport or a mode that sets a viewport takes precedence. Non-pixel viewport globals are ignored. A story viewport can also be assigned through globals.viewport.value.

Use the current Modes API, not legacy viewports

The older parameters.chromatic.viewports setting is an array of widths. Chromatic describes it as replaced by Modes and says it plans to deprecate it. Chromatic converts legacy entries to modes during capture, but the legacy viewports and current modes APIs cannot be used at the same time. For a new setup, use Modes. See Chromatic’s legacy viewports page and its parameters and globals reference.

Configure viewport size in other supported test runners

Chromatic also documents runner-specific viewport settings. Use the setting for the runner executing the capture rather than assuming the Storybook configuration applies everywhere.

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.
  • Vitest: Set the browser viewport in vitest.config or call page.viewport(width, height) at the test level.
  • Playwright: Configure use.viewport in a project, or use test.use({ viewport }).
  • Cypress: Set viewportWidth and viewportHeight globally or at test level. Chromatic’s current documentation says cy.viewport() is unsupported for Chromatic capture.

Runner details are listed in Chromatic’s cross-runner viewport guide.

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

Troubleshoot common viewport problems

  • The capture is not clipped at the configured height: Viewport dimensions set the browser size; full rendered height is captured by default. Enable parameters.chromatic.cropToViewport: true if clipping is intended.
  • A mode dimension is rejected: Use whole-number pixel dimensions within Chromatic’s documented 200–2560-pixel range. Do not use rem or calc() as mode dimensions.
  • Snapshots multiply unexpectedly: Each applied mode has a separate snapshot and baseline. Narrow the modes to stories or components that actually need responsive review.
  • Legacy and current settings conflict: Do not combine chromatic.viewports with chromatic.modes; migrate to Modes.
  • A Cypress test’s viewport change is ignored: Chromatic documents cy.viewport() as unsupported. Configure viewportWidth and viewportHeight in Cypress settings instead.
  • A very large snapshot fails or changes scale: Check the snapshot pixel total and browser image-dimension limits; Chromatic may retry affected Safari or Firefox captures at DPR 1.0.

Or skip the browser setup

If you need a website screenshot rather than Chromatic’s Storybook visual-test workflow, ScreenshotNeo can return an image or PDF from one request. For example, save a WebP screenshot of a page with cURL:

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

See the ScreenshotNeo API documentation for request options. It removes cookie banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, failed loads, timeouts, and cache hits are not billed. Its MCP server lets AI agents take screenshots. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000.

Sign up for ScreenshotNeo’s free plan.

Frequently Asked Questions

Can I use a viewport width such as 320 pixels in Chromatic Modes?

No. Chromatic’s documented minimum width or height is 200 pixels, so 320 pixels is within range.

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

Does setting a Chromatic viewport automatically create a cropped screenshot?

No. Chromatic captures the rendered UI’s full height by default; enable cropToViewport to clip to the configured height.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.