Viewport Size Calculator
Our web & development tool computes viewport size accurately. Enter your inputs for detailed analysis and optimization tips.
Reviewed for accuracy by Daniel Agrici, Founder & Lead Developer
Viewport Size Calculator
Calculator
Adjust values & calculateEnter your values below. Every result is computed in your browser โ no data is sent to any server.
Formula: CSS Width = Screen Width / DPR | Viewport Height = CSS Height - Browser Chrome | 1vw = CSS Width / 100 | 1vh = Viewport Height / 100
Worked example โ CSS Viewport: 1920 x 1000px | 1vw = 19.20px | 1vh = 10.00px | Breakpoint: xl
Formula
CSS Width = Screen Width / DPR | Viewport Height = CSS Height - Browser Chrome | 1vw = CSS Width / 100 | 1vh = Viewport Height / 100
Screen resolution is divided by the device pixel ratio to get CSS pixel dimensions. Browser chrome (address bar, tabs) is subtracted from the height to get the actual viewport height. Viewport units are calculated as 1% of the respective viewport dimension.
Worked Examples
Example 1: Standard Desktop Monitor
Problem:A developer has a 1920x1080 monitor with DPR 1 and wants to know the CSS viewport dimensions and viewport unit values.
Solution:CSS Width = 1920 / 1 = 1920px CSS Height = 1080 / 1 = 1080px Viewport Height = 1080 - 80 (browser chrome) = 1000px 1vw = 1920 / 100 = 19.20px 1vh = 1000 / 100 = 10.00px 1vmin = min(19.20, 10.00) = 10.00px 1vmax = max(19.20, 10.00) = 19.20px Breakpoint: xl (desktop)
Result:CSS Viewport: 1920 x 1000px | 1vw = 19.20px | 1vh = 10.00px | Breakpoint: xl
Example 2: Retina Mobile Device
Problem:An iPhone 14 Pro has a screen resolution of 1179x2556 with DPR 3. Calculate the CSS viewport and responsive breakpoint.
Solution:CSS Width = 1179 / 3 = 393px CSS Height = 2556 / 3 = 852px Viewport Height = 852 - 80 = 772px 1vw = 393 / 100 = 3.93px 1vh = 772 / 100 = 7.72px Breakpoint: xs (mobile) since 393 < 640 Orientation: Portrait
Result:CSS Viewport: 393 x 772px | 1vw = 3.93px | 1vh = 7.72px | Breakpoint: xs (mobile)
Frequently Asked Questions
What is a viewport in web development?
A viewport is the visible area of a web page that the user can see without scrolling. It differs from the total page size because web pages can extend beyond the visible screen area. On desktop browsers, the viewport is the browser window minus the address bar, tabs, and other browser chrome. On mobile devices, the viewport is the entire screen area available to web content. Understanding viewport dimensions is critical for responsive design because CSS media queries, viewport units, and layout calculations all depend on the viewport size rather than the physical screen resolution.
What is the difference between screen resolution and CSS viewport size?
Screen resolution refers to the actual physical pixels on a display, while CSS viewport size is measured in CSS pixels (also called device-independent pixels). Modern devices often have a device pixel ratio (DPR) greater than 1, meaning multiple physical pixels represent a single CSS pixel. For example, an iPhone 14 Pro has a physical resolution of 1179 x 2556 pixels but a CSS viewport of 393 x 852 pixels because its DPR is 3. This distinction matters because CSS layout, media queries, and viewport units all operate on CSS pixels, not physical pixels. Designers must account for DPR when preparing images to ensure they appear sharp on high-density displays.
What are viewport units (vw, vh, vmin, vmax) and how are they used?
Viewport units are CSS length units relative to the viewport dimensions. One vw equals 1% of the viewport width, and one vh equals 1% of the viewport height. The vmin unit equals 1% of whichever viewport dimension is smaller, while vmax equals 1% of the larger dimension. These units are extremely useful for creating fluid typography, full-screen sections, and responsive layouts without media queries. For example, setting font-size to 4vw makes text scale proportionally with the browser width. A common pattern is using min() or clamp() with viewport units to set boundaries, like clamp(16px, 2.5vw, 24px) for responsive but constrained text sizing.
What are common responsive design breakpoints?
The most widely used breakpoint system comes from Tailwind CSS: sm at 640px, md at 768px, lg at 1024px, xl at 1280px, and 2xl at 1536px. Bootstrap uses slightly different values: sm at 576px, md at 768px, lg at 992px, xl at 1200px, and xxl at 1400px. These breakpoints correspond roughly to mobile phones, tablets, laptops, and desktops. However, modern responsive design increasingly favors container queries and fluid layouts over fixed breakpoints. When choosing breakpoints, base them on where your content naturally breaks rather than targeting specific device widths, since the variety of screen sizes in use today makes device-specific breakpoints impractical.
How does device pixel ratio affect web development?
Device pixel ratio (DPR) is the ratio of physical pixels to CSS pixels on a display. A DPR of 2 means each CSS pixel is rendered using a 2x2 grid of physical pixels (4 total physical pixels). This primarily affects image rendering. Images displayed at their natural size on a 2x DPR screen will appear blurry because each image pixel is stretched across 4 physical pixels. To display crisp images, you need to serve images at 2x (or 3x) their CSS display size. The srcset attribute and the picture element allow developers to serve different image sizes based on DPR. Canvas elements also need to account for DPR by scaling the canvas buffer size.
What is the difference between visual viewport and layout viewport on mobile?
Mobile browsers have two viewport concepts. The layout viewport is the full-width area used for CSS layout calculations and is controlled by the viewport meta tag. Without the meta tag, mobile browsers use a default layout viewport around 980px wide and shrink the page to fit the screen. The visual viewport is the portion of the page currently visible on screen, which changes when users pinch-to-zoom. When zoomed in, the visual viewport is smaller than the layout viewport. The meta tag viewport with width=device-width and initial-scale=1.0 synchronizes the layout viewport to the device width, which is essential for mobile-responsive design.
How do I handle viewport changes for responsive layouts?
Viewport dimensions change when users resize their browser window, rotate their device, or when the virtual keyboard appears on mobile. In CSS, media queries automatically respond to viewport changes. In JavaScript, you can listen for the resize event on the window object or use the more modern ResizeObserver API. The visualViewport API provides precise information about the visual viewport, including offset and scale. For mobile keyboards, the visualViewport resize event is more reliable than the window resize event. Modern CSS features like container queries allow components to respond to their container size rather than the viewport, which is often more practical for component-based architectures.
What is the viewport meta tag and why is it important?
The viewport meta tag is an HTML meta element that controls how the browser renders the page on mobile devices. The most common setting is width=device-width, initial-scale=1.0, which tells the browser to set the layout viewport width equal to the device CSS width and start at 100% zoom. Without this tag, mobile browsers default to a virtual viewport of about 980px and scale the entire page down to fit, making text tiny and requiring users to zoom in. Additional properties include maximum-scale, minimum-scale, and user-scalable, though restricting zoom via user-scalable=no is strongly discouraged for accessibility reasons because it prevents visually impaired users from zooming in.
How do I calculate the correct image sizes for different viewports?
To calculate optimal image sizes, multiply the CSS display width by the device pixel ratio. If an image displays at 400 CSS pixels wide on a device with DPR 2, you need an 800-pixel-wide image for crisp rendering. For responsive images, calculate the image width at each breakpoint. A full-width hero image on a 1920px viewport needs a 1920px source (or 3840px for 2x displays). Use the sizes attribute with srcset to tell the browser which image to download. For example, sizes with 100vw for mobile and 50vw for desktop viewports paired with multiple srcset sources allows the browser to pick the best match. Tools like Viewport Size Calculator help determine the exact pixel dimensions needed at each breakpoint and DPR combination.
What are safe areas and how do they affect viewport calculations?
Safe areas are inset regions on modern devices where content should be placed to avoid being obscured by hardware features like notches, rounded corners, or home indicators. Apple introduced the concept with the iPhone X notch, and CSS provides the env() function with safe-area-inset-top, safe-area-inset-bottom, safe-area-inset-left, and safe-area-inset-right values. To use safe areas, add viewport-fit=cover to the viewport meta tag and apply padding using env() values. For example, padding-bottom set to env(safe-area-inset-bottom) prevents content from hiding behind the home indicator. These insets reduce the usable viewport area, so calculations for full-screen layouts must account for safe area deductions to ensure content remains accessible on all devices.
References
Background & Theory
History
Reviewed for accuracy by Daniel Agrici, Founder & Lead Developer ยท Editorial policy
Related Calculators
๐งฎFile Size Converter
Calculate file size converter with inputs, formulas, and instant results.
๐งฎRag Chunk Size Calculator
Calculate optimal chunk sizes for RAG retrieval based on embedding model, overlap, and context.
๐งฎDocker Container Size Calculator
Estimate Docker image and container sizes from base image, layers, and dependencies.
๐งฎOpen Graph Image Size Calculator
Calculate optimal Open Graph and Twitter Card image dimensions for social media sharing.
๐งฎGit Repository Size Calculator
Estimate repository size growth based on commit frequency, file sizes, and branching strategy.
๐งฎNpm Package Size Calculator
Check the install size and download time impact of adding an npm package to your project.
๐งฎDatabase Size Calculator
Estimate database storage needs from table count, rows per table, and average row size.
๐งฎBackup Size Calculator
Calculate backup storage needs based on data volume, retention policy, and change rate.