Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk5 min

How to Set the Viewport in Cypress

Use cy.viewport() for an in-test resize, or configure viewportWidth and viewportHeight for project or test defaults. Includes presets, orientation, and troubleshooting.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use cy.viewport(width, height) to set a viewport during a test, or set viewportWidth and viewportHeight in Cypress configuration for project defaults. For example, cy.viewport(1280, 720) switches the application under test to a 1280 × 720 viewport.

Set the viewport inside a test

Call cy.viewport() in the test at the point where you want the app to render at a different size. Cypress supports exact dimensions or a named preset:

As an Amazon Associate I earn from qualifying purchases.

describe('responsive layout', () => {
  it('shows the desktop navigation at 1280 × 720', () => {
    cy.viewport(1280, 720);
    cy.visit('/');
    cy.get('[data-testid="desktop-navigation"]').should('be.visible');
  });

  it('uses the iPhone 6 portrait preset', () => {
    cy.viewport('iphone-6');
    cy.visit('/');
    cy.get('[data-testid="mobile-menu"]').should('be.visible');
  });
});

The documented command forms are cy.viewport(width, height) and cy.viewport(preset, orientation). Both can also take an options object. The command is chained from cy, yields null, and is not itself a value to assert on. Numeric dimensions must be finite, non-negative numbers. See the Cypress viewport API reference for the current command signature.

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

Choose exact dimensions or a preset

Use numeric dimensions when your test needs a specific breakpoint or an exact repeatable canvas. Presets are a convenient shorthand when a documented device-like viewport is sufficient. The API currently documents these preset dimensions:

#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
Preset Dimensions
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

Preset names and dimensions are API details that may change; check the current reference before relying on a particular one. Orientation defaults to portrait. Pass 'landscape' to reverse a preset’s width and height:

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

Set project-wide default dimensions

For a default that applies across your project, set viewportWidth and viewportHeight in Cypress configuration. Cypress documents default dimensions of 1000 × 660 pixels.

import { defineConfig } from 'cypress';

export default defineConfig({
  e2e: {
    viewportWidth: 1280,
    viewportHeight: 720,
  },
});

Use the configuration file for project defaults rather than repeating the same cy.viewport() call in every test. The configuration reference documents the available configuration locations and precedence: Cypress configuration.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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

Override dimensions from the command line or environment

For a one-off run with different dimensions, pass configuration values to Cypress:

npx cypress run --config viewportWidth=1280,viewportHeight=720

You can also override them with the environment variables CYPRESS_VIEWPORT_WIDTH and CYPRESS_VIEWPORT_HEIGHT.

Scope dimensions to a suite or test

When only a particular suite or test needs another viewport, use test-specific configuration rather than changing the project default. Cypress restores the prior/default viewport dimensions after the scoped test configuration ends.

Rank #3
Sale
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.
describe('mobile layout', { viewportWidth: 375, viewportHeight: 667 }, () => {
  it('shows the mobile navigation', () => {
    cy.visit('/');
    cy.get('[data-testid="mobile-menu"]').should('be.visible');
  });
});

it('checks one tablet-sized view', { viewportWidth: 768, viewportHeight: 1024 }, () => {
  cy.visit('/');
  cy.get('[data-testid="tablet-layout"]').should('be.visible');
});

Use this scope when the dimensions belong to the test’s setup, not as a mid-test transition. For a test that deliberately changes size as it runs, call cy.viewport() at each transition.

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

Understand viewport size versus the runner preview

The viewport is the size Cypress uses for the application under test. In the Cypress app, the runner may scale and center that application preview to fit the available window; this visual zoom does not change the app’s viewport calculations or behavior. A preview that looks smaller on screen does not mean the test is using smaller CSS viewport dimensions. See Cypress open mode.

What viewport emulation does—and does not—test

A preset gives your web app a viewport size and orientation; it does not reproduce every property of a physical phone. Cypress documents that devicePixelRatio is not simulated. Viewport checks are useful for responsive mobile-web layouts, but they are not native mobile-app tests. Cypress says it cannot run native mobile apps, while it can control mobile-web viewports; its FAQ addresses the distinction.

Rank #4
Sale
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor | 100Hz, Game Mode, Advanced Eye Comfort, HDMI and D-sub Ports (LS27D366GANXZA)
  • 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

Make responsive and visual checks repeatable

For screenshot-based visual checks, keep the viewport fixed and generate and compare screenshots in the same environment. Viewport dimensions are one controlled comparison condition; changing them between baseline and comparison can change wrapping, breakpoints, and page height independently of a UI change. Cypress’s guidance is in Visual testing in Cypress.

  • Choose explicit width and height for breakpoint tests, rather than relying on the runner window size.
  • Keep the viewport consistent between the screenshot used as a baseline and the screenshot under comparison.
  • When testing portrait and landscape, define them as separate cases so the expected layout is clear.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting viewport issues

Cypress.config() throws when changing viewport dimensions

Since Cypress 16.0.0, changing viewportWidth or viewportHeight through Cypress.config() while a test is executing throws an error. That change would affect the next test, rather than resizing the running test. Use cy.viewport(width, height) for an in-test change, or set dimensions in suite- or test-specific configuration. See the viewport API and configuration reference.

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

The app appears small in the Cypress runner

Check the runner’s preview scaling before changing test dimensions. Cypress can scale the preview to fit the runner window without changing the viewport the app uses. Use explicit viewport dimensions in the test when the behavior depends on a particular size.

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 preset name or dimensions do not match expectations

Confirm that the preset exists in the current viewport API reference and verify its documented dimensions. Preset names and values are versioned API details. If the exact width and height matter, use numeric dimensions instead.

A mobile viewport does not reproduce a physical phone

Viewport size and orientation alone do not simulate devicePixelRatio or native-app behavior. Treat the test as a responsive web check, not a complete device simulation.

Or skip the browser setup

If your goal is to capture a website screenshot rather than test application behavior, ScreenshotNeo provides a screenshot API and MCP server. A single request can return an image or PDF. For example, this cURL request saves a WebP screenshot:

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

See the ScreenshotNeo API documentation for request options and response details. Cookie banners are accepted and removed before capture, along with known newsletter popups and chat widgets; these steps can be turned off. Bot checks, blank pages, failed loads and cache hits are not billed, and response headers report the page verdict and billing status. An MCP server lets AI agents use screenshot tools. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000.

Sign up for ScreenshotNeo’s free plan.

Frequently Asked Questions

Does Cypress reset the viewport between tests?

Yes. Cypress resets the viewport to its default size between tests; scoped test configuration returns to the prior/default dimensions afterward.

Can I use Cypress viewport presets to test a native mobile app?

No. Cypress viewport controls apply to web content and do not make Cypress a native mobile-app test runner.

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.

Leave a Reply

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

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.

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
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

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.