px to vh
px to vh converts a pixel size into viewport and font-relative CSS units, so a design made for one screen scales on others.
What px to vh does
px to vh converts a pixel size into viewport and font-relative CSS units, so a design made for one screen scales on others. Front-end developers use it when turning a fixed mockup into a responsive layout.
Enter the pixel value, the screen height and width your design was made for, and the root font size. You get the size in vh, vw and rem, the percentage of screen height, and a quick check of how many pixels 10vh equals on that screen. The defaults are a 1440 by 900 screen and a 16px root font.
How to use px to vh
- Type the pixels
Enter the size from your design, such as 120.
- Set the screen
Enter the height and width of the screen the design was drawn for.
- Set the root font
Keep 16 unless your site changes the html font size.
- Copy the unit
Use the vh, vw or rem value in your stylesheet.
Questions about px to vh
How do I convert px to vh?
Divide the pixels by the screen height and multiply by 100. On a 900px-tall screen, 120px is 13.333vh.
Should I use vh or rem?
Use vh or vw for sizes that should follow the screen, such as full-height sections. Use rem for text and spacing that should follow the reader's font settings.
Why does 100vh look too tall on phones?
Browser toolbars on phones can cover part of the screen. Newer CSS units such as dvh handle this, but this tool works in vh.