PX to VH Converter
Convert pixel values to viewport height units instantly. This tool is useful for responsive layouts, fluid design and building UI that adapts to different screen sizes.
Enter a value in px or vh and the converter updates automatically. It works in both directions, so you can edit either field and get an accurate conversion based on the current viewport height.
The calculation uses the browser's viewport height at the moment of conversion. Since 1vh equals 1 percent of the viewport height, the result changes if the user resizes the window or rotates their device.
PX to VH Formula
vh = (px / viewport-height) * 100To convert pixels (px) to viewport height units (vh), divide the pixel value by the height of the viewport and multiply the result by 100.
This method is useful for creating vertical layouts that scale with the user's screen size. Since vh depends on the actual height of the device, elements adapt naturally across different resolutions and orientations.
| Pixels (px) | VH |
|---|---|
| 4px | 0.44vh |
| 8px | 0.89vh |
| 12px | 1.33vh |
| 16px | 1.78vh |
| 20px | 2.22vh |
| 24px | 2.67vh |
| 32px | 3.56vh |
| 40px | 4.44vh |
| 48px | 5.33vh |
| 64px | 7.11vh |
Why Use VH Instead of PX?
VH units are useful when building layouts that need to scale with the height of the user's screen. Unlike fixed pixel values, vh adapts to the actual viewport height, making your design more responsive and consistent across devices.
When users switch between portrait and landscape modes or view your site on different screen sizes, elements defined with vh adjust automatically. Pixel-based measurements remain static, which can break vertical spacing or lead to cropped content.
- Adaptive vertical layout: elements scale with the viewport height instead of staying fixed.
- Better responsiveness: ideal for full-screen sections, hero blocks, and vertically centered content.
- Consistent appearance: behaves predictably across devices with different screen heights.
- Reduced media queries: fewer manual adjustments for different resolutions.
Best Practices for Using VH
Using <code>vh</code> units helps create layouts that adapt to the user's actual screen height. Below are the most reliable best practices for using vh effectively in modern responsive design.
- Use vh for full-height sections: hero blocks, splash screens, and intro sections work best when sized relative to the viewport height.
- Use vh for vertical centering: combining vh with flexbox or grid helps maintain consistent alignment across devices.
- Avoid relying on px for large vertical spacing: pixel values don't scale with screen height and may look cramped or oversized on different devices.
- Don't use vh for text sizes: viewport-based typography can cause readability issues on very tall or very short screens.
- Be careful with 100vh on mobile: mobile browsers have dynamic UI bars, so 100vh may exceed the visible area. Prefer <code>100svh</code>, <code>100lvh</code> or <code>100dvh</code> when supported.
- Combine vh with media queries when needed: some layouts require minimum or maximum heights to avoid extreme scaling.
- Test in landscape and portrait modes: viewport height changes drastically when rotating a device, so ensure the layout remains balanced.
Following these practices keeps your VH-based layouts predictable, responsive and visually stable across all screen sizes and device orientations.
How VH Works in CSS
The vh unit is based on the height of the browser's viewport. One vh equals 1% of the visible viewport height. This makes vh ideal for creating sections that scale automatically with the user's screen size.
For example, if the viewport height is 900px, then:
1vh = 9pxWhen you define layout dimensions using <code>vh</code>, the browser recalculates the pixel value dynamically whenever the viewport size changes — such as when rotating a mobile device or resizing a window. This allows for responsive vertical spacing without fixed pixel values.
- Viewport–based: all vh values reference the current height of the browser window, not fonts or parent elements.
- Dynamic recalculation: vh updates immediately when the user resizes the window or changes orientation.
- Independent of content: unlike percentages, vh does not rely on parent element dimensions — only the screen height.
- Useful for full-screen sections: hero blocks, splash screens and intro layouts scale naturally with the viewport.
In short, vh gives you direct control over vertical scaling, making it one of the most powerful units for responsive layouts, especially on modern devices with widely varying screen sizes.
How To Use VH
Using vh units is straightforward once you understand how they behave. Each vh represents 1% of the viewport height, making it ideal for building layouts that scale with the user's screen. VH is commonly used for hero sections, fullscreen blocks, responsive vertical spacing and fluid layouts.
1. Use vh for fullscreen sections
A classic use case is a hero block that always fills the entire screen height:
section {
height: 100vh;
}This ensures your section always takes up the full viewport height, regardless of device or window size.
2. Create responsive vertical spacing
For layouts where the spacing should scale with screen height, vh is more flexible than fixed pixels:
div {
margin-top: 5vh;
padding-bottom: 3vh;
}This keeps vertical rhythm consistent on devices with very different heights.
3. Mix vh with px for precise control
Use vh for large-scale responsive layout changes, and px for small details like borders, icons and fine UI elements:
button {
height: 6vh;
border: 1px solid #ccc;
}This avoids the layout becoming too loose or too tight on extreme screen sizes.
4. Be aware of mobile browser UI
On mobile, the browser's address bar affects the viewport height. Modern CSS fixes this using dvh and svh, but vh still works well for most static layouts.
section {
height: 100dvh; /* more stable on mobile */
}Use <code>dvh</code> if you need precise and stable height values on mobile devices.
5. Test on multiple screen sizes
Resize your browser or test on different devices. If your sections and spacing scale smoothly, you're using vh correctly.
By combining vh for vertical scaling with px for fine details, you get a responsive and clean layout that adapts naturally to modern screens and orientations.
Related Converters:
REM to PX Converter
Instantly calculate rem to pixelEM to PX Converter
Instantly calculate em to pixelVH to PX Converter
Instantly calculate vh to pixelVW to PX Converter
Instantly calculate vw to pixelPX to VW Converter
Instantly calculate pixel to vwPX to Percent Converter
Instantly calculate pixel to percent