How to Set a Custom Viewport Size in Chrome DevTools
In this article
Testing how your website looks on different screen sizes is essential for responsive design. Instead of resizing your browser window manually, Chrome DevTools lets you set a precise custom viewport size—down to the pixel. This guide shows you how to do it in a few clicks, plus how to save custom presets for quick testing.
What You'll Need
- Google Chrome (any recent version, desktop)
- A webpage you want to test (local or online)
Step-by-Step
- Open Chrome DevTools. On the page you want to test, right-click anywhere and select Inspect, or press F12 / Ctrl+Shift+I (Windows/Linux) or Cmd+Option+I (Mac).
- Toggle device toolbar. In DevTools, click the Toggle device toolbar icon (a rectangle with a phone outline) in the top-left corner. Alternatively, press Ctrl+Shift+M (Windows/Linux) or Cmd+Shift+M (Mac). The viewport will change to a simulated device.
- Select “Responsive” mode. At the top of the page, you’ll see a dropdown showing device names (e.g., iPhone 12, iPad). Click it and choose Responsive—this lets you freely resize the viewport.
- Set the custom width and height. On the left side of the device toolbar, you’ll see two numeric fields: the first is width, the second is height. Click each field, type your desired pixel values, and press Enter. The viewport immediately resizes to those exact dimensions.
- Use the drag handles (optional). If you prefer dragging, move your cursor to the right or bottom edge of the viewport. When it turns into a resize arrow, click and drag to adjust the size. The width/height fields update live.
- Save a custom preset (optional). After typing your width and height, click the “Add device” button (a plus icon) next to the size fields. A dialog appears. Give it a name (e.g., “My Tablet”), and click Add. The preset now appears in the device dropdown for future use.
- Exit device mode. To return to normal browsing, click the Toggle device toolbar icon again (or press the same shortcut). Your viewport returns to the browser window size.
Common Mistakes
- Forgetting to press Enter after typing the width or height—the value won’t apply until you do.
- Using the browser’s own zoom instead of the device toolbar. This doesn’t change the viewport size; it only scales the page visually.
- Not setting both dimensions. If you only change width, the height may stay at a default, which can misrepresent the aspect ratio.
- Confusing device pixel ratio with viewport size. The size you set is in CSS pixels, not physical screen pixels. A device with a 3x DPR will still show the same CSS viewport.
Tips
- Use presets for common breakpoints. Save 375×667 (mobile), 768×1024 (tablet), and 1366×768 (laptop) to switch quickly.
- Test with the device toolbar’s “Show media queries” feature. Click the three-dot menu in the toolbar and enable “Show media queries” to see colored bars that help you inspect breakpoints.
- Combine with throttling. Use the network throttling dropdown (e.g., Slow 3G) to simulate real-world conditions alongside the custom viewport.
- Use the “Capture screenshot” option. From the three-dot menu, choose “Capture screenshot” to save an image of the viewport at the exact size you set.
- Keep the device toolbar open while editing CSS. You can resize the viewport and watch styles update in real time, which speeds up responsive debugging.
Troubleshooting
- The viewport doesn’t change when I type numbers. Make sure you pressed Enter after typing. If it still doesn’t work, click the width field, select all, and type again.
- The device toolbar is missing. If you don’t see the toggle icon, you might be in a different DevTools layout. Click the three-dot menu in DevTools and select “Dock to right” or “Dock to bottom” to see the toolbar.
- My custom preset doesn’t appear. After saving, look in the device dropdown—it’s listed alphabetically under “Device” names. If it’s still not there, try clearing DevTools cache or restarting Chrome.
- The page looks different from what I expect. Check the device pixel ratio (DPR) setting in the toolbar. If it’s set to a high value (e.g., 3.0), the page renders as if on a retina screen, which may change layout. Set DPR to 1.0 for a standard view.
- I can’t resize the viewport below 50px. Chrome DevTools has a minimum width of 50px for the viewport. For smaller sizes, use the “Responsive” mode and type a value, but note the minimum.
Frequently Asked Questions
Does the custom viewport size affect how the page loads on a real device?
No. It only simulates the viewport in your browser. The actual device’s screen size and resolution are not changed.
Can I set a custom viewport size in Firefox or Safari?
Yes. Firefox has a similar “Responsive Design Mode” (Ctrl+Shift+M), and Safari’s “Responsive Design Mode” (Cmd+Ctrl+R) works similarly. The steps are slightly different but the concept is the same.
What’s the difference between viewport size and screen size?
Viewport size is the visible area of the webpage (in CSS pixels), while screen size is the physical display resolution. The viewport can be smaller than the screen, especially on mobile devices.
Why does my page look different at the same viewport size on different devices?
Because of device pixel ratio (DPR) and CSS media queries. A device with a higher DPR renders more physical pixels, but the CSS viewport is the same. Media queries may also target specific features like hover or pointer type.
Can I set a custom viewport size without opening DevTools?
You can resize your browser window manually, but for precise pixel dimensions, DevTools is the standard method. Alternatively, you can use browser extensions that simulate viewports.
How do I reset back to the default browser size?
Simply toggle the device toolbar off (click the icon again). The viewport returns to the size of your browser window.