Conversion Table
Em | Viewport Height |
---|---|
0.01em | 0.0148vh |
0.03em | 0.0444vh |
0.05em | 0.0741vh |
0.08em | 0.1185vh |
0.1em | 0.1481vh |
0.15em | 0.2222vh |
0.2em | 0.2963vh |
0.5em | 0.7407vh |
0.625em | 0.9259vh |
0.75em | 1.1111vh |
0.875em | 1.2963vh |
1em | 1.4815vh |
1.125em | 1.6667vh |
1.25em | 1.8519vh |
1.375em | 2.0370vh |
1.5em | 2.2222vh |
1.625em | 2.4074vh |
1.75em | 2.5926vh |
1.875em | 2.7778vh |
2em | 2.9630vh |
2.125em | 3.1481vh |
2.25em | 3.3333vh |
2.375em | 3.5185vh |
2.5em | 3.7037vh |
2.625em | 3.8889vh |
2.75em | 4.0741vh |
2.875em | 4.2593vh |
3em | 4.4444vh |
3.125em | 4.6296vh |
3.25em | 4.8148vh |
3.375em | 5.0000vh |
3.5em | 5.1852vh |
3.625em | 5.3704vh |
3.75em | 5.5556vh |
3.875em | 5.7407vh |
4em | 5.9259vh |
5em | 7.4074vh |
6em | 8.8889vh |
8em | 11.8519vh |
10em | 14.8148vh |
15em | 22.2222vh |
20em | 29.6296vh |
30em | 44.4444vh |
40em | 59.2593vh |
50em | 74.0741vh |
60em | 88.8889vh |
80em | 118.5185vh |
100em | 148.1481vh |
Differences Between em and vh
Em is a relative unit that scales according to the font size of the element it is used on. Viewport Height (vh) is a relative unit that scales according to 1% of the height of the viewport. Em units are useful for scalable and responsive design, while vh units provide a way to size elements relative to the viewport height.
Advantages of Using em
Using em units allows for better scalability and flexibility in web design. Since em is relative to the font size of the parent element, it enables elements to scale proportionally. This is useful for responsive design and for respecting user preferences for font size.
How to Convert em to vh
To convert em to viewport height, you need to know the font size of the element and the viewport height. The formula for conversion is:
vh = em * (font size * 100 / viewport height)
For example, to convert 2em to viewport height, assuming the font size is 16px and the viewport height is 1080px:
2em * (16px * 100 / 1080px) = 2.963vh
Frequently Asked Questions
Why should I use em instead of vh?
Using em allows for more scalable and flexible layouts within the context of the current element's font size, improving the responsiveness and accessibility of your design.
How do I set the font size?
You can set the font size using CSS on the parent element. For example:
parent-element {
font-size: 16px;
}
Can I use em for all elements?
Yes, you can use em for most elements to ensure consistency and scalability within the context of the current element's font size.