PX to VW formula
vw = px ÷ viewport width × 100
One vw is 1% of the viewport width, so you work out what fraction of the screen your pixel value is and turn it into a percentage. Viewport height works the same way with the height: vh = px ÷ viewport height × 100. Converting px to vw is how you turn a fixed measurement from a design file into a size that scales with the screen.
Worked examples
- 24px on a 1440px desktop frame: 24 ÷ 1440 × 100 = 1.6667vw
- 16px on a 375px mobile frame: 16 ÷ 375 × 100 = 4.2667vw
- A 320px image on a 768px tablet frame: 320 ÷ 768 × 100 = 41.6667vw
- 64px of top padding on a 900px-tall screen: 64 ÷ 900 × 100 = 7.1111vh
PX to VW conversion table (1440px viewport)
1440px is a common desktop design width. At this size 1vw = 14.4px.
| Pixels | VW | Pixels | VW |
|---|---|---|---|
| 1px | 0.0694vw | 48px | 3.3333vw |
| 2px | 0.1389vw | 64px | 4.4444vw |
| 4px | 0.2778vw | 80px | 5.5556vw |
| 8px | 0.5556vw | 96px | 6.6667vw |
| 12px | 0.8333vw | 120px | 8.3333vw |
| 14px | 0.9722vw | 160px | 11.1111vw |
| 16px | 1.1111vw | 240px | 16.6667vw |
| 18px | 1.25vw | 320px | 22.2222vw |
| 20px | 1.3889vw | 480px | 33.3333vw |
| 24px | 1.6667vw | 720px | 50vw |
| 32px | 2.2222vw | 960px | 66.6667vw |
| 40px | 2.7778vw | 1440px | 100vw |
Converting vw back to px
To check what a vw value will look like on a given screen, reverse the formula: px = vw × viewport width ÷ 100. This is the quickest way to spot a value that won't work everywhere. A heading set to 5vw is:
- 18.75px on a 375px phone (5 × 375 ÷ 100)
- 72px on a 1440px laptop (5 × 1440 ÷ 100)
- 96px on a 1920px monitor (5 × 1920 ÷ 100)
The size more than quintuples across that range, which is why viewport-based sizes almost always need a minimum and a maximum.
When to use vw and vh
Viewport units suit things that should be sized relative to the screen rather than to the text: full-width hero sections, large display headings, decorative shapes, and gaps that should open up on wide monitors. They're also the moving part inside fluid type, where a size grows smoothly between a phone and a desktop.
Vh is useful for sections that should fill the screen, like min-height: 100vh on a landing hero. On mobile, the browser toolbar changes the visible height, so the newer svh, lvh and dvh units are often a better fit. MDN's viewport units reference lists all of them.
Common mistakes
- Pure vw font sizes. Text set only in vw doesn't get larger when the user zooms, and it scales to extremes on very small and very large screens. Wrap it in
clamp()with rem limits. The CSS clamp() generator does the maths for you. - Using the wrong frame width. Convert against the width of the design frame the value came from. 24px from a 375px mobile mockup is 6.4vw, not 1.6667vw.
- Setting width: 100vw on full-bleed sections. 100vw includes the scrollbar on many desktop setups and causes a sideways scroll. Use
width: 100%where you can. - Forgetting rem for most text. Body copy and UI labels usually belong in rem. Use the px to rem converter for those.
Frequently asked questions
How many pixels is 1vw?
1vw is 1% of the viewport width. On a 1440px-wide screen 1vw is 14.4px, on a 375px phone it is 3.75px. The pixel value changes every time the window width changes.
What is the difference between vw and %?
Vw is always a percentage of the browser viewport. Percent is usually a percentage of the parent element, so width: 50% inside a 600px container is 300px, while 50vw is half the screen no matter where the element sits.
Does 100vw include the scrollbar?
Yes. 100vw is the full viewport width including any classic vertical scrollbar, so an element set to width: 100vw can be slightly wider than the page and cause a horizontal scrollbar. Width: 100% avoids that.
Should I use vh or dvh on mobile?
On mobile browsers, 100vh is often taller than the visible area because the address bar shrinks and grows. The newer svh, lvh and dvh units give the small, large and dynamic viewport height. Dvh tracks the visible area as the toolbar moves.
Is it bad to set font sizes in vw?
Font sizes in pure vw do not grow when a user zooms, which can fail WCAG 1.4.4 Resize Text, and they get tiny on phones and huge on wide monitors. Combine vw with rem inside clamp() so the text has a minimum and maximum size.