VW to PX Converter

Convert vw to px and px to vw for any screen width. 5vw is 18.75px on a 375px phone and 72px on a 1440px laptop, which is why vw-only font sizes go wrong.

Pixels → viewport units

Viewport units → pixels

–

CSS Viewport Units Explained: vw, vh, vmin, vmax, dvh, svh and lvh

Viewport units let you size things relative to the browser window instead of a parent element: a hero that fills the screen, a heading that grows with the window, a panel that’s always half the screen tall. They’re easy to use, but they come with two well-known traps, one on mobile and one on desktop.

Mobile 100vh section hidden behind the browser toolbar compared with 100dvh fitting the screen

The basic units

UnitEquals
1vw1% of the viewport width
1vh1% of the viewport height
1vmin1% of the smaller of width and height
1vmax1% of the larger of width and height

On a 1440 × 900 browser window, 10vw = 144px and 10vh = 90px. On a 390 × 844 phone, 10vw = 39px. The viewport unit converter above converts both ways for common device sizes.

There are also logical versions, vi and vb (inline and block direction), which follow the writing mode, useful for vertical languages.

The conversion formulas

  • px = value × viewport dimension ÷ 100
  • value = px ÷ viewport dimension × 100

48px on a 1440px-wide screen is 48 ÷ 1440 × 100 = 3.333vw. The same 3.333vw on a 390px phone is just 13px, which shows why viewport units need limits.

Trap 1: 100vh on mobile

On mobile browsers, the address bar and toolbar slide in and out as you scroll. Originally, browsers defined 100vh as the height with toolbars hidden, the largest possible viewport, so that layouts wouldn’t jump while scrolling. The side effect: a height: 100vh section is taller than the visible screen when the page first loads, and content at the bottom (like a call-to-action button) is hidden behind the browser toolbar.

The fix: small, large and dynamic viewport units

New units, supported in all major browsers since 2022–2023, describe each case explicitly:

UnitBased onUse
svh (small)Viewport with browser UI fully shownContent that must always be fully visible
lvh (large)Viewport with browser UI hiddenSame as the old vh behaviour
dvh (dynamic)Current viewport, updates as UI shows/hidesFull-screen sections that should always fit

There are matching svw, lvw, dvw, svmin and so on.

.hero { min-height: 100vh; min-height: 100dvh; }

The first line is a fallback for older browsers. dvh can cause content to resize while the user scrolls, so for many layouts svh is the calmer choice: always fits, never jumps.

Trap 2: 100vw causes horizontal scrolling

On desktop operating systems with classic scrollbars (Windows, Linux, and macOS with “always show scroll bars”), 100vw includes the vertical scrollbar’s width. An element set to width: 100vw is therefore about 15–17px wider than the visible content area, creating a horizontal scrollbar.

Fixes:

  • Use width: 100% for full-width elements inside the page flow.
  • For “full-bleed” elements breaking out of a centered container, use techniques based on the container’s width, or CSS Grid with named full-width columns.
  • scrollbar-gutter: stable reserves scrollbar space consistently, which reduces layout jumps but doesn’t change what 100vw means.

Typography with viewport units

Sizing text purely in vw is a classic mistake. It becomes tiny on phones and huge on wide monitors, and it doesn’t respond properly to browser zoom, which can fail WCAG 1.4.4 (Resize Text). Combine vw with rem inside clamp():

h1 { font-size: clamp(2rem, 1.2rem + 3vw, 4rem); }

Our fluid typography guide explains the formula.

Container query units

Viewport units are relative to the whole window, but components often live in containers of different widths: a card might appear in a narrow sidebar or a wide main column. Container query units solve this:

UnitRelative to
cqw / cqh1% of the query container’s width / height
cqi / cqb1% of the container’s inline / block size
cqmin / cqmaxSmaller / larger of cqi and cqb

Set container-type: inline-size on the parent, and children can size text and spacing with cqi instead of vw. Supported in all major browsers since 2023.

Percentages versus viewport units

UnitRelative toTypical use
% (width)Parent’s widthColumns, images inside containers
% (height)Parent’s height, only if the parent has a defined heightOften confusing; prefer other methods
vw / vhBrowser viewportFull-screen sections, fluid type with clamp()
dvh / svhViewport accounting for mobile UIMobile full-height layouts
cqiComponent’s containerResponsive components

Percentage heights often “don’t work” because the parent has no explicit height. Viewport units sidestep this, which is why min-height: 100vh became the go-to way to make full-height layouts.

Hero sections, sticky footers and fluid gaps

  • Full-screen hero on mobile: min-height: 100svh; (with a 100vh fallback).
  • Sticky footer layout: body as a flex column with min-height: 100dvh, main content flex: 1.
  • Fluid section padding: padding-block: clamp(3rem, 8vh, 8rem).
  • Modal max height: max-height: 90dvh; overflow: auto;.
  • Square that fits the screen: width: 80vmin; height: 80vmin;.