Viewport Calculator

Calculate and convert between pixels and viewport units (vw, vh, vmin, vmax) for responsive web design.

Viewport Settings

Current viewport: 0 x 0

Pixel to Viewport

Viewport to Pixel

Viewport

1920 x 1080

Aspect Ratio: 16:9

16px Converted

VW

0.8333vw

VH

1.4815vh

VMIN

1.4815vmin

VMAX

0.8333vmax

Viewport to Pixels

0vw =

0.00px

0vh =

0.00px

Diagonal
2202.91px
Total Pixels
20,73,600

What Are Viewport Units?

Viewport units are CSS length units that are relative to the size of the browser's viewport — the visible area of the web page. Unlike pixels, which are fixed, viewport units scale automatically as the browser window is resized or as a user switches between devices. This makes them a foundational tool for building truly responsive web designs without relying on media queries for every dimension.

There are four viewport units defined in the CSS specification:

  • vw (viewport width) — 1vw equals 1% of the viewport's total width. On a 1920px-wide screen, 1vw = 19.2px.
  • vh (viewport height) — 1vh equals 1% of the viewport's total height. On a 1080px-tall screen, 1vh = 10.8px.
  • vmin — 1vmin equals 1% of the smaller of the viewport width or height. On a 1920×1080 display, 1vmin = 10.8px (based on height, the smaller dimension).
  • vmax — 1vmax equals 1% of the larger of the viewport width or height. On a 1920×1080 display, 1vmax = 19.2px (based on width, the larger dimension).

Viewport units were introduced in CSS3 and are now supported across all modern browsers, including Chrome, Firefox, Safari, and Edge. They are especially valuable for full-screen layouts, responsive typography, and elements that need to maintain proportional sizing regardless of the screen resolution or device type.

Understanding the relationship between pixels and viewport units is essential for front-end developers who need to translate fixed design specifications (usually provided in pixels by designers) into fluid, responsive CSS values. This viewport calculator automates those conversions instantly.

Viewport Unit Conversion Formulas

The conversions between pixels and viewport units follow straightforward proportional math. Each formula expresses the pixel value as a percentage of the relevant viewport dimension. Here is a full breakdown of all conversions this calculator performs:

Pixels to Viewport Units

  • px → vw: Divide pixel value by viewport width, then multiply by 100.
  • px → vh: Divide pixel value by viewport height, then multiply by 100.
  • px → vmin: Divide pixel value by the smaller of width or height, then multiply by 100.
  • px → vmax: Divide pixel value by the larger of width or height, then multiply by 100.

Viewport Units to Pixels

  • vw → px: Multiply vw value by viewport width, then divide by 100.
  • vh → px: Multiply vh value by viewport height, then divide by 100.

Viewport Diagonal

The pixel diagonal is calculated using the Pythagorean theorem: the square root of (width² + height²). This gives the total diagonal pixel count of the viewport, which is useful when working with diagonal-based layouts or understanding screen geometry.

Pixel to Viewport Unit Conversion

vw = (px / viewportWidth) × 100 | vh = (px / viewportHeight) × 100 | vmin = (px / min(W,H)) × 100 | vmax = (px / max(W,H)) × 100 | vw→px = (vw / 100) × viewportWidth | diagonal = √(W² + H²)

Where:

  • px= Pixel value to convert
  • viewportWidth (W)= Total width of the viewport in pixels
  • viewportHeight (H)= Total height of the viewport in pixels
  • vw= Result in viewport width units (1 vw = 1% of viewport width)
  • vh= Result in viewport height units (1 vh = 1% of viewport height)
  • vmin= Result in vmin units (1% of the smaller viewport dimension)
  • vmax= Result in vmax units (1% of the larger viewport dimension)
  • diagonal= Viewport diagonal length in pixels via Pythagorean theorem

When to Use Viewport Units in Responsive Design

Viewport units shine in specific responsive design scenarios where you want elements to scale fluidly with the browser window rather than jumping between fixed sizes via media query breakpoints. Knowing when to reach for vw, vh, vmin, or vmax can dramatically simplify your CSS.

Full-Viewport Sections

Setting height: 100vh on a hero section ensures it fills the entire visible screen on every device, from a small phone to a widescreen monitor. No breakpoints needed. This pattern is ubiquitous in modern landing pages and portfolio sites.

Fluid Typography

Responsive typography using viewport units like font-size: 4vw ensures text scales smoothly with the viewport. Combining this with clamp() — for example, font-size: clamp(1rem, 2.5vw, 2rem) — lets you set a minimum and maximum size so text is never too small on mobile or too large on desktop.

Proportional Images and Videos

Using width: 80vw; height: 45vw on a video container maintains a 16:9 aspect ratio across all viewport sizes, which was a common technique before the aspect-ratio CSS property became widely available.

Sticky Sidebars and Modals

Setting a modal or overlay to width: 100vw; height: 100vh makes it cover the full viewport regardless of scroll position. Combined with position: fixed, this is the standard approach for full-screen overlays.

Vmin for Square Elements

When you need an element that stays square and fills the available space on both portrait and landscape orientations (such as a game board or avatar), width: 80vmin; height: 80vmin achieves this with a single rule. The square will always fit within the viewport without overflow, regardless of device rotation.

Common Device Viewport Sizes Reference

Understanding the viewport dimensions of popular devices helps developers make informed decisions when designing breakpoints and testing layouts. The following table lists common device viewport widths and heights as used in this calculator's preset buttons.

Device Width (px) Height (px) Aspect Ratio
iPhone SE 375 667 375:667
iPhone 12/13 390 844 195:422
iPhone 14 Pro Max 430 932 215:466
iPad 768 1024 3:4
iPad Pro 1024 1366 512:683
Laptop (HD) 1366 768 683:384
Desktop Full HD 1920 1080 16:9
4K UHD 3840 2160 16:9

Keep in mind that viewport width in CSS refers to the logical pixel width reported by the browser, not the physical hardware pixels. On high-DPI (Retina) displays, a device with 750 physical pixels wide may report a viewport of 375 CSS pixels. This is the value relevant for CSS viewport unit calculations.

Pixels vs. Viewport Units: Choosing the Right Unit

A common question for developers learning responsive design is when to use fixed pixel values versus fluid viewport units. Both have their place, and choosing correctly leads to more maintainable and better-performing CSS.

Use Pixels When:

  • You need a fixed, consistent size regardless of screen size — icons, border widths, border radii, and small UI elements like checkboxes often benefit from pixel values that don't shrink below a usable size.
  • You are setting minimum or maximum constraints within a clamp() or min()/max() function.
  • You want to prevent font size scaling on mobile zoom — though for accessibility reasons, rem is usually preferred over px for font sizes.

Use Viewport Units When:

  • You want an element to fill a proportion of the screen — full-screen heroes, modals, and sidebars.
  • You are building fluid typography that should scale smoothly between small and large screens.
  • You need device-agnostic sizing for elements like game boards, carousels, or image grids that should always be proportional to the visible area.
  • You are targeting landscape vs. portrait orientation changes with vmin or vmax.

In practice, modern CSS layout often combines both: a container might use max-width: 1200px with width: 90vw to be fluid on small screens while capping on large ones. Understanding the pixel-to-vw relationship — which this calculator provides instantly — is key to tuning these hybrid approaches precisely.

Worked Examples

Convert 320px to VW on a 1920px-wide Desktop

Problem:

A designer specifies a sidebar that is 320px wide. You need to express this in vw units for a 1920px viewport so it scales proportionally.

Solution Steps:

  1. 1Identify inputs: pixelValue = 320, viewportWidth = 1920
  2. 2Apply formula: vw = (320 / 1920) × 100
  3. 3Calculate: 320 / 1920 = 0.16667
  4. 4Multiply by 100: 0.16667 × 100 = 16.6667vw

Result:

320px = 16.6667vw on a 1920px-wide viewport. Use width: 16.6667vw in your CSS.

Convert 5vw to Pixels on an iPhone SE (375px wide)

Problem:

You have an element styled as 5vw. You need to know how many pixels wide it will actually render on an iPhone SE with a 375px CSS viewport width.

Solution Steps:

  1. 1Identify inputs: vwValue = 5, viewportWidth = 375
  2. 2Apply formula: px = (vwValue / 100) × viewportWidth
  3. 3Calculate: (5 / 100) × 375
  4. 4Simplify: 0.05 × 375 = 18.75px

Result:

5vw renders as 18.75px on an iPhone SE. This is useful for checking whether text or UI elements will be large enough on small screens.

Find Vmin and Vmax for a 768×1024 iPad Viewport

Problem:

For a 768×1024 iPad viewport, calculate what 1vmin and 1vmax equal in pixels to understand proportional sizing for both portrait and landscape layouts.

Solution Steps:

  1. 1Viewport: W = 768px, H = 1024px. min(768, 1024) = 768. max(768, 1024) = 1024.
  2. 2For 1px → vmin: (1 / 768) × 100 = 0.1302vmin. So 1vmin = 768/100 = 7.68px.
  3. 3For 1px → vmax: (1 / 1024) × 100 = 0.0977vmax. So 1vmax = 1024/100 = 10.24px.
  4. 4Diagonal: √(768² + 1024²) = √(589824 + 1048576) = √1638400 = 1280px

Result:

On a 768×1024 iPad: 1vmin = 7.68px, 1vmax = 10.24px, diagonal = 1280px. This is a classic 3:4:5 Pythagorean triple scaled by 256.

Convert a 24px Heading to VH on a 1080px-tall Display

Problem:

A 24px font size needs to be expressed in vh units for a 1920×1080 viewport so it is proportional to the screen height.

Solution Steps:

  1. 1Identify inputs: pixelValue = 24, viewportHeight = 1080
  2. 2Apply formula: vh = (24 / 1080) × 100
  3. 3Calculate: 24 / 1080 = 0.022222
  4. 4Multiply by 100: 0.022222 × 100 = 2.2222vh

Result:

24px = 2.2222vh on a 1080px-tall viewport. Note: using vh for font sizes is generally not recommended for body text since it doesn't respect user zoom settings; prefer clamp() with vw or rem for typography.

Tips & Best Practices

  • Use the 'Use Current Viewport' button to auto-populate your real browser dimensions for accurate, context-specific conversions.
  • For fluid typography, combine viewport units with clamp(): font-size: clamp(1rem, 2.5vw, 2rem) prevents text from becoming too small or too large.
  • On mobile, prefer 100dvh over 100vh for full-screen sections to avoid issues with browser UI overlapping the viewport.
  • Use vmin for square elements that should always fit within the viewport in both portrait and landscape orientations.
  • The diagonal calculation uses the Pythagorean theorem — useful when working with CSS transforms that involve diagonal animations or SVG viewBox scaling.
  • When converting designer specs (always in px) to responsive CSS, use this calculator to find the vw equivalent once, then verify by entering that vw value back in the reverse converter.
  • The aspect ratio output uses the GCD algorithm to reduce to the simplest form — a 1920×1080 viewport correctly shows 16:9, confirming standard widescreen proportions.
  • For padding and margin that should scale with the viewport, vw is often preferable to percentages since it stays consistent regardless of element nesting depth.

Frequently Asked Questions

vw is always relative to the viewport width specifically, while vmin is relative to whichever of the width or height is smaller. On a landscape display where width > height, vmin uses the height as its reference; on a portrait display, vmin uses the width. This makes vmin ideal for elements that should fit within the viewport regardless of orientation, such as a square game board or profile image that should never overflow in either portrait or landscape mode.
On mobile browsers like Chrome for Android and Safari on iOS, the browser UI (address bar, navigation controls) can overlap the viewport, making the actual visible area smaller than 100vh. This is a known issue where 100vh is calculated based on the maximum viewport size (when the browser UI is hidden) rather than the current visible height. CSS has introduced the dynamic viewport units dvh, svh, and lvh to address this: dvh tracks the dynamic visible height, svh uses the smallest viewport height, and lvh uses the largest. For the most reliable full-height layouts on mobile, consider using 100dvh with a 100vh fallback.
Yes, but with caveats. Using pure viewport units like font-size: 4vw for body text means the text will be very small on mobile and very large on wide monitors, potentially breaking readability. The modern best practice is to use the CSS clamp() function: font-size: clamp(1rem, 2.5vw, 1.5rem) sets a minimum size of 1rem, a preferred fluid size of 2.5vw, and a maximum of 1.5rem. This gives you fluid scaling between devices while ensuring text is always within a readable range.
Percentage units in CSS are relative to the element's containing block (usually the parent element), while viewport units are always relative to the browser window. For example, width: 50% on a div inside a 600px-wide container gives 300px, whereas width: 50vw always gives 50% of the total viewport width regardless of nesting. This distinction matters greatly for deeply nested elements: percentages cascade and depend on parent context, while viewport units remain absolute relative to the screen.
The viewport diagonal — calculated as √(width² + height²) — gives the straight-line pixel distance across the viewport from corner to corner. While not a CSS unit itself, it's useful for understanding the geometric properties of a viewport, approximating the physical size of a display when combined with PPI data, and for certain canvas-based or SVG animations that use diagonal-based scaling. Some developers also use it to verify aspect ratio consistency across different resolutions.
The calculator automatically detects your current browser viewport size when the page loads and displays it at the top of the inputs panel. Click the 'Use Current Viewport' button to populate the width and height fields with your actual browser window dimensions. This lets you instantly see exactly what any pixel value converts to in your real browsing environment, which is far more useful than working with hypothetical dimensions alone.
The four core viewport units — vw, vh, vmin, and vmax — have excellent browser support and are available in all modern browsers including Chrome, Firefox, Safari, Edge, and Opera, as well as their mobile counterparts. They have been supported since 2014 in all major browsers. The newer dynamic viewport units (dvh, svh, lvh) introduced to solve mobile browser UI overlap have support in Chrome 108+, Firefox 101+, and Safari 15.4+, covering the vast majority of users as of 2025.

Sources & References

Last updated: 2026-06-05

💡

Help us improve!

How would you rate the Viewport Calculator?

<>

Editorial Note

MyCalcBuddy Editorial Team

This page is maintained as an educational calculator reference.

Source

Formula Source: Standard Mathematical References

by Various

UpdatedLast reviewed: May 2026
CheckedFormula checks are based on standard references and internal QA review.