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

Use cy.viewport(width, height) to change the application viewport while a Cypress test is running. For a project-wide default, set viewportWidth and viewportHeight in Cypress configuration. These settings control the page’s CSS layout area; they are separate from the headless browser display size used for screenshots and videos.

Choose the right Cypress size control

“Screen size” can mean two different things in Cypress. Decide which one you need before changing a setting:

  • Application viewport: the width and height available to your page’s responsive CSS and JavaScript. Use cy.viewport(), test configuration, project configuration, CLI options, or environment variables.
  • Browser display size: the outer display canvas used by a headless browser. Configure it in the before:browser:launch event when the requirement concerns captured screenshots or videos.

Changing the browser display size does not change viewportWidth or viewportHeight. Conversely, changing the application viewport does not emulate every property of a physical device, such as its device-pixel ratio.

Change the application viewport inside a test

Call cy.viewport() before the actions and assertions that should run at the new size:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB
  • CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
  • WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
  • A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents
describe('responsive header', () => {
  it('shows the mobile navigation', () => {
    cy.viewport(390, 844)
    cy.visit('/')

    cy.get('[data-testid="desktop-nav"]').should('not.be.visible')
    cy.get('[data-testid="mobile-menu"]').should('be.visible')
  })
})

The command accepts a width and height in pixels. It can be called again later in the same test, which makes it suitable for checking several breakpoints:

it('checks desktop and mobile layouts', () => {
  cy.visit('/')

  cy.viewport(1440, 900)
  cy.get('[data-testid="desktop-nav"]').should('be.visible')

  cy.viewport(390, 844)
  cy.get('[data-testid="mobile-menu"]').should('be.visible')
})

Set the viewport before cy.visit() when the initial page load itself must occur at that size. If you change it after visiting, Cypress resizes the existing application and the page can react through its normal resize handlers.

Use Cypress device presets

Named presets are shorthand for documented width and height pairs:

cy.viewport('iphone-6')
cy.viewport('iphone-6', 'landscape')

For landscape orientation, Cypress reverses the preset’s width and height. The current API documentation lists these preset dimensions:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Preset Portrait dimensions (px)
ipad-2, ipad-mini 768 × 1024
iphone-3, iphone-4 320 × 480
iphone-5 320 × 568
iphone-6, iphone-7, iphone-8, iphone-se2 375 × 667
iphone-6+ 414 × 736
iphone-x 375 × 812
iphone-xr 414 × 896
macbook-11 1366 × 768
macbook-13 1280 × 800
macbook-15 1440 × 900
macbook-16 1536 × 960
samsung-note9 414 × 846
samsung-s10 360 × 760

These are Cypress configuration presets, not measurements of current device market share or complete device emulation. The available names can change between Cypress versions, so verify the current API list when a preset is part of a long-lived test suite.

Test a responsive matrix of sizes

Prefer explicit dimensions that exercise your application’s actual CSS breakpoints. A device name is useful shorthand, but the assertion should verify behavior: navigation visibility, column count, menu state, or another user-visible change.

Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB
  • CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
  • SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
const viewports = [
  { name: 'mobile', width: 390, height: 844 },
  { name: 'tablet', width: 768, height: 1024 },
  { name: 'desktop', width: 1440, height: 900 },
]

describe('layout at supported breakpoints', () => {
  for (const size of viewports) {
    it(`renders the ${size.name} layout`, () => {
      cy.viewport(size.width, size.height)
      cy.visit('/')

      if (size.width < 768) {
        cy.get('[data-testid="mobile-menu"]').should('be.visible')
      } else {
        cy.get('[data-testid="desktop-nav"]').should('be.visible')
      }
    })
  }
})

Include widths just below, at, and just above important breakpoints when you need boundary coverage. Avoid asserting only that an element exists; assert whether it is visible, hidden, stacked, or reordered as your design requires.

Set a default viewport in project configuration

For a baseline used by most tests, add the dimensions to cypress.config.js:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const { defineConfig } = require('cypress')

module.exports = defineConfig({
  viewportWidth: 1000,
  viewportHeight: 660,
})

Cypress documents 1000 × 660 pixels as the default application viewport. A project setting prevents every test from repeating the same command, while an individual test can still override it with cy.viewport().

Apply a size to one suite or test

Use test configuration when an entire suite shares a size and should return to the previous defaults afterward:

describe('tablet layout', {
  viewportWidth: 768,
  viewportHeight: 1024,
}, () => {
  it('shows the tablet navigation', () => {
    cy.visit('/')
    cy.get('[data-testid="tablet-nav"]').should('be.visible')
  })
})

it('uses a large desktop viewport', {
  viewportWidth: 1536,
  viewportHeight: 960,
}, () => {
  cy.visit('/')
  cy.get('[data-testid="desktop-nav"]').should('be.visible')
})

This scope-specific approach keeps responsive intent next to the tests that depend on it. Cypress restores the prior defaults after the configured suite or test completes.

Override the viewport for a command-line run or CI job

Run the same test suite with different defaults without editing the configuration file:

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.
Rank #3
Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
  • Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
  • Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
  • Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
  • In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
  • Ultra-thin bezels: Maximize your viewing experience with thin bezels.
cypress run --config viewportWidth=1280,viewportHeight=720

Cypress also maps configuration keys to environment variables. In a Unix-like shell:

export CYPRESS_VIEWPORT_WIDTH=800
export CYPRESS_VIEWPORT_HEIGHT=600
cypress run

These overrides are useful when a CI job needs a controlled baseline. Record the dimensions in the job configuration so a failed run can be reproduced locally.

Cypress 16: do not mutate viewport config during a running test

Beginning with Cypress 16.0.0, changing viewportWidth or viewportHeight through Cypress.config() while a test is executing is disallowed. Earlier behavior could affect the next test rather than the current one. Replace code such as:

// Do not use this during a test in Cypress 16+
Cypress.config('viewportWidth', 1280)
Cypress.config('viewportHeight', 720)

with an in-test command:

cy.viewport(1280, 720)

Or put the values in suite/test configuration, project configuration, a CLI --config override, or environment variables.

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.

When the preview looks smaller than the configured size

In Cypress Open Mode, the runner scales and centers the preview to fit the available pane. That visual scaling does not alter the application’s calculated viewport or responsive behavior. The Cypress interface displays the current size and scale. To investigate a layout failure, trust measurements and assertions in the page rather than the apparent physical size of the runner pane.

Control the headless browser display size

If your goal is the canvas of a headless screenshot or video, configure the browser launch options in the before:browser:launch event. This is separate from the page viewport:

Rank #4
Sale
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor
  • CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
  • SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
  • MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
  • KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
  • INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient
// cypress.config.js
const { defineConfig } = require('cypress')

module.exports = defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      on('before:browser:launch', (browser, launchOptions) => {
        if (browser.isHeadless) {
          launchOptions.args.push('--window-size=1440,900')
        }
        return launchOptions
      })
    },
  },
})

The exact launch argument depends on the browser and execution mode. Consult Cypress’s browser-launch API for the supported event details. Keep the application dimensions explicit with cy.viewport() or configuration even when you also set a display size.

Screenshot behavior and reliable capture

Use Cypress’s screenshot API after the page reaches the state you intend to capture:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
cy.get('[data-testid="report"]').should('be.visible')
cy.screenshot('report-desktop', { capture: 'fullPage' })

A full-page capture can include content beyond the current viewport, but it does not turn a device preset into physical-device emulation. If a screenshot is the deliverable, distinguish the page layout viewport from the browser’s display canvas and document both settings in CI.

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

Troubleshooting viewport problems

The layout does not change after calling cy.viewport()

  • Call the command before the assertion that depends on the new size.
  • If the initial load must use the size, call it before cy.visit().
  • Check that your application listens to resize events and that the breakpoint is actually crossed.
  • Assert on responsive behavior rather than a device label.

Cypress.config() throws an error

On Cypress 16 and later, runtime changes to viewportWidth and viewportHeight are not permitted. Use cy.viewport() or scoped test configuration instead.

The Open Mode preview appears too small

The runner is scaling the preview to fit its pane. Check the displayed viewport dimensions and your application’s computed layout; the scaling itself does not change test behavior.

The screenshot or video has the wrong outer dimensions

You may have changed only the application viewport. Configure the headless browser display through before:browser:launch, then keep the application viewport setting separate.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Sale
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
  • 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
  • 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.

A named preset is unknown

Preset names are version-sensitive. Check the current Cypress viewport API, or replace the name with an explicit width and height.

CI results differ from local results

Compare Cypress versions, browser choice, project defaults, CLI overrides, environment variables, and headless display settings. Print or otherwise record the intended viewport for each job so the effective configuration is visible in logs.

Or skip the browser setup

For a direct website screenshot outside Cypress, ScreenshotNeo provides a single API request. Its clean-shot pipeline accepts cookie and consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be disabled. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. It also offers an MCP server for Claude, Cursor, and other MCP clients, with take_screenshot, get_page_info, and capture_pdf tools.

See the ScreenshotNeo API documentation for all options, including viewport and device presets, full-page capture, lazy-image loading, CSS selectors, dark mode, retina scale, PDF settings, custom CSS and JavaScript, click actions, waits, request blocking, headers, cookies, user agents, authorization, timezone, geolocation, transparent backgrounds, resizing, TTL caching, signed image links, asynchronous webhooks, bulk capture, usage reporting, and the OpenAPI specification.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

The same request in Python:

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)

And in Node.js:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

ScreenshotNeo’s Free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 shots, and every feature is included on every plan. Create a free ScreenshotNeo account to try the API.

FAQ

Does cy.viewport() change device pixel ratio?

No. It changes the application’s CSS viewport dimensions; it is not complete physical-device emulation.

Can I use a different viewport for each test?

Yes. Call cy.viewport() in each test or provide dimensions in that test’s configuration.

Should I test named devices or numeric breakpoints?

Use names for readable shorthand, but include numeric widths that correspond to your application’s actual responsive breakpoints.

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

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.