Here explains the difference between all CSS metrics.
IN
Units of EM values are the most complicated to work with. It is abstract and arbitrary. Here is an example, 1em
is equal to the current font size of the element in question, that is, if you have not yet set font size anywhere on the page, then it will automatically pick up the default font size of the browser, which is probably 16px
. Then, it is defined that by default 1em = 16px
. Say you set the tag body { font-size:20px }
then the 1em
will become 20px
. How it works.
Another example: If you create a tag h1 { font-size: 2em; }
, the size of H1 in px
will be 32px
if you haven’t set some value yet in css.
Percentage %
Percentage as the name says works with value percentage. If a parent has the size of 20px
, and you define the child with font-size:50%
it will be the size of 10px
.
The percentage is very good to work with the tools to grow and decrease the size on the text page.
So when is it advantageous to use in? And the to use % in the entire layout and get satisfactory result?
– ropbla9
It is not a matter of being advantageous. You should choose the metrica that best suits your layout structure. Yes, you can use
%
and have a cool result, it depends on who will mount the page.– Antony Alkmim