Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the relationship between ems and pixels?

What is the value of an em in terms of pixels?

10em = ?px ?

like image 689
Ralph The Mouf Avatar asked Sep 22 '09 22:09

Ralph The Mouf


3 Answers

There's no specific relationship between em and px. It's computed based on the width of the "m" character for each font-face.

like image 153
Mark Hurd Avatar answered Oct 06 '22 02:10

Mark Hurd


While as others have said, there is no set ratio - as it varies from font to font - it is possible to calculate this for a particular font face/size combination by using DHTML.

Simply create a div with

style="width: 1em; visibility:hidden"

and append it to the place in the document you are interested about.

You can then find out its width by checking the div's clientWidth property

like image 38
levik Avatar answered Oct 06 '22 02:10

levik


It depends on the font and the platform you're rendering on. There is no universal ratio.

like image 28
Frank Farmer Avatar answered Oct 06 '22 02:10

Frank Farmer