Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do CSS ems always represent the font size?

Tags:

css

font-size

From what I know, the em keyword in CSS means the current size of a font.

So if you put 1.2 em, it means 120% of the font height.

It doesn't seem right though that em is used for setting the width of divs etc like YUI grids does:

margin-right:24.0769em;*margin-right:23.62em;

Everytime I read about em, I forget what it really represents.

I'm hoping someone can explain it to me so it sticks in my head heeh.

like image 736
public static Avatar asked Dec 01 '22 08:12

public static


2 Answers

Historically it is the width of an "M" in the font. Hence the name! In CSS2.1 it is defined to be the same as the font-size.

In many cases it seems more natural to use em rather than points or pixels, because it is relative to the font size. For example you might define a text-column to have a width of 40em. If you later decide to change the font-size, the column will still keep the same number of letters per line.

like image 171
JacquesB Avatar answered Dec 04 '22 01:12

JacquesB


Traditionally, em is the width of the upper case M. In practise though, an em is the point size of the font.

em dash versus en dash.

like image 26
Apocalisp Avatar answered Dec 04 '22 01:12

Apocalisp