tags:

views:

62

answers:

6

I am still not clear what does size in em mean?
I have worked px, pt in CSS.
What would 0.8, 1.0 and 1.2 em mean?
I have seen height's in CSS like: height: 0.8em; or height: 1.2em;
How is it calculated?

+1  A: 

An em is the width of the letter "m" (in your current font and size).

Paul Schreiber
This is not actually so, it's an urban myth :-) Some fonts don't even _have_ an "m" and even those that do have the width of their 'm's sometimes less than an em: http://en.wikipedia.org/wiki/Em_%28typography%29
paxdiablo
It's not an urban myth, it's just a deprecated use of the term. http://www.adobe.com/uk/type/topics/glossary.html#ememspaceemquad
dreamlax
+2  A: 
Haim Evgi
+2  A: 

1em is equal to the current font size. 2em means 2 times the size of the current font. E.g., if an element is displayed with a font of 12 pt, then '2em' is 24 pt. The 'em' is a very useful unit in CSS, since it can adapt automatically to the font that the reader uses.

more here

Sotiris
+1  A: 

Paul is correct, however its "M" not "m". However this is an esoteric definition derived from typesetting/printing and isnt of much use in this case. In terms of whats going to be useful to you you its a percentage of font size.

prodigitalson
No, he really isn't :-)
paxdiablo
Well i was getting ready to clarify with neraly exactly ehat it says in the Wiki article you linked to so :-P
prodigitalson
+1  A: 

Em is the size of a character. It will vary depending upon the font size. If the font size is 24 then 2Em will be equal to the space it should take to hold two characters of the font size 24.

As quoted from wiki.

An em is a unit of measurement in the field of typography. This unit defines the proportion of the letter width and height with respect to the point size of the current font.

FYI: En is half of Em. 0.5Em

Rakesh Juyal
+3  A: 

The meaning of "em" has changed over the years. Not all fonts have the letter "M" in them (for example, Chinese), but all fonts have a height. The term has therefore come to mean the height of the font – not the width of the letter "M."

A very clear and informative example:

Let's look at a simple example where we use the em unit to set font sizes:

<HTML>
  <STYLE>
    H1 { font-size: 2em }
  </STYLE>
  <BODY>
    <H1>Movies</H1>
  </BODY>
</HTML>

When used to specify font sizes, the em unit refers to the font size of the parent element. So, in the previous example, the font size of the H1 element is set to be twice the font size of the BODY element. To find what the font size of the H1 element will be, we need to know the font size of BODY. Because this isn't specified in the style sheet, the browser must find it from somewhere else – a good place to look is in the user's preferences. So, if the user sets the normal font size to 10 points, the size of the H1 element is 20 points. This makes document headlines stand out relative to the surrounding text. Therefore: Always use ems to set font sizes!

More Info

simplyharsh
awesome explanation :) +1
Rakesh Juyal