PX to EM Conversion

PX to EM Conversion


PX to EM Conversion
Everything is sized relative to its parent element.
The meaning of an em changes as elements are nested.
For the conversion we have to follow the following steps - 
1. First of all, Set a default font size which usually is 16px.
2. After setting the default value now we can convert a pixel value to em, based on the default size. 
3.  As well as convert an em value to pixels, based on the same default font size.
We will try to understand that with an example -
This example will clear all concepts related to px to em conversion - 
Example -
Suppose you have a div of which have size of 16 px 
And you have a paragraph inside which is 2em then it will be 32px.
And suppose another paragraph with 0.5 em then it will be 8px.
If you have another paragraph nested then 2 em will mean 64px.
Output -