User Agents

Web browsers and everyday web tech, explained

How to Set Browser Viewport Size (Chrome, Firefox, Safari)

· 5 min read · Browsers

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Setting the browser viewport size lets you preview how a website looks on different screen dimensions—like a phone, tablet, or desktop—without resizing the actual window. This is essential for responsive design testing and for taking consistent screenshots. You can do it using built-in developer tools in most browsers, or by manually resizing the window. No special software is required.

What You'll Need

  • A modern web browser (Chrome, Firefox, Safari, or Edge).
  • The website or local file you want to test.
  • Optional: a list of target viewport sizes (e.g., 375×667 for iPhone SE, 768×1024 for iPad).

Step-by-Step

  1. Open Developer Tools. In Chrome, Firefox, or Edge (Windows/Linux): press F12 or Ctrl+Shift+I (Mac: Cmd+Option+I). In Safari, first enable the Develop menu: go to Safari > Settings > Advanced and check “Show features for web developers.” Then press Option+Cmd+I.
  2. Activate the device toolbar. In Chrome and Edge, click the toggle icon that looks like a rectangle with a phone outline (top-left of DevTools). In Firefox, click the “Responsive Design Mode” icon (two overlapping rectangles) in the toolbar. In Safari, click the “Toggle Responsive Design Mode” icon (a rectangle with a phone) in the Develop menu or toolbar.
  3. Choose a preset device. The toolbar shows a dropdown at the top with common devices like iPhone, iPad, or Pixel. Select one to instantly set the viewport to that device’s screen size.
  4. Enter a custom size. If you need a specific width and height, click the width and height fields (usually next to the device dropdown) and type your values. Press Enter to apply.
  5. Rotate the viewport (optional). Click the rotate icon (a circular arrow) to switch between portrait and landscape orientations. This swaps the width and height.
  6. Test responsiveness with media queries. While in responsive mode, you can drag the right or bottom edge of the viewport to resize it fluidly. The page will re-render as if the browser window were that size.
  7. Take a screenshot (optional). In Chrome/Edge, click the three-dot menu in the device toolbar and choose “Capture screenshot” or “Capture full size screenshot.” In Firefox, right-click the viewport and select “Take a Screenshot.”
  8. Exit responsive mode. Click the same toggle icon again to return to the normal browser window.

Common Mistakes

  • Forgetting to enable the Develop menu in Safari. Without it, you can’t open DevTools or access responsive mode.
  • Setting the viewport but not the device pixel ratio. Some tools only change CSS pixels, not the physical pixel ratio. For accurate mobile testing, use the device presets that include the correct DPR.
  • Resizing the actual browser window instead of using the toolbar. This works but is less precise and doesn’t simulate device-specific behaviors like touch events.
  • Not clearing the cache after changing viewport. Some sites serve different assets based on user agent or viewport; a hard refresh (Ctrl+Shift+R) ensures you see the latest version.

Tips

  • Use the device presets for standard screen sizes, but also test extreme sizes (e.g., 320px wide) to catch overflow issues.
  • Keep a list of common breakpoints: 320, 375, 414, 768, 1024, 1280, 1920.
  • In Chrome, you can save custom device presets via the device dropdown > “Edit” > “Add custom device.”
  • Use the “Responsive” option in the dropdown to freely drag the viewport to any size.
  • Check both portrait and landscape for mobile layouts.

Troubleshooting

  • The device toolbar doesn’t appear. Make sure you’re in the DevTools panel, not the main browser window. If you’re in Firefox, the responsive mode icon is in the toolbar at the top of the browser, not inside DevTools.
  • Viewport size doesn’t match what I entered. Some browsers add scrollbars or toolbars that affect the visible area. In Chrome, you can hide the device toolbar’s “device frame” to get the exact size. Also, check that the “Zoom” in DevTools is set to 100%.
  • The page looks different from a real phone. This is common because emulation doesn’t replicate hardware features like touch or performance. Use a real device or browser’s remote debugging for final testing.
  • Safari doesn’t have the responsive mode icon. Ensure you’ve enabled the Develop menu in Safari’s advanced settings, then restart Safari.

Frequently Asked Questions

What is the difference between viewport size and screen size?

Viewport size is the visible area of the browser window (excluding toolbars, scrollbars, and browser chrome). Screen size is the physical resolution of the display. In responsive mode, you set the viewport, not the screen.

Can I set the viewport size without using developer tools?

Yes, you can manually resize the browser window to a specific pixel size using your operating system’s window resize feature, but it’s less precise. Some browser extensions also allow quick viewport presets.

How do I set the viewport size for a screenshot in a headless browser?

Tools like Puppeteer or Playwright allow you to set the viewport via script, e.g., page.setViewport({width: 375, height: 667}). This is common for automated testing.

Does changing the viewport affect the actual device?

No, it only changes the rendering in the browser. It does not alter your physical screen or other devices.

Why does my website look different on a real phone than in responsive mode?

Emulation doesn’t account for hardware differences, touch events, or device-specific CSS features. Also, some browsers use a different user agent in responsive mode, which can trigger server-side changes.

Can I set the viewport to a size larger than my screen?

Yes, in responsive mode you can enter any size, even larger than your monitor. The browser will show a scrollable area. However, performance may be affected for very large sizes.