tags:

views:

315

answers:

5

what is the difference px,em and ex? Amd when you define font-size in css, do i use px,pt or em?

+1  A: 

what is the difference px,em and ex?

http://www.w3.org/TR/CSS21/syndata.html#length-units describes those and the other length units available in CSS

Amd when you define font-size in css, do i use px,pt or em?

As a rule of thumb, use percentages on screen and pt for print.

David Dorward
+2  A: 

http://www.w3schools.com/css/css_units.asp

em depends on the user's browser size

px is absolute

one ex is the x-height of a font (x-height is usually about half the font-size)

Please search a little bit before asking here.

remi bourgarel
+1 for recommending search.
macek
@remi:i actually did some search on the web,found a lot of definitions...i just wanted to get some wisdom from people who has had real life experiences in using them in their projects,...thanks 4 ur comments
manraj82
w3c is your BFF. In W3c We trust.
remi bourgarel
w3s is not w3c; in w3s we complain about huge amounts of advertising (mostly for themselves) and errors.
David Dorward
A: 
  • pm are pixels.
  • em is based on the width of the 'm' letter on the current font
  • ex is based on the height of the 'x' letter on the current font.

Have a look here : read at section 3.4.2

See also wikipedia

David V.
em is not based on the width of an 'm'. A typographic em is the width of an **M**, and a CSS em is the font-size.
David Dorward
Mixed typography and CSS. I stand corrected. edit: That being said, a search reveals that many sites fall for the same mistake.
David V.
David V., the wikipedia article you linked to is titled, *Em (typography)*. So yes, you are wrong. CSS `em` is equivalent to element `font-size`.
macek
I linked the wikipedia article to provide further information. I admit that was confusing.
David V.
A: 
**em**: the 'font-size' of the relevant font
**ex**: the 'x-height' of the relevant font
**px**: pixels, relative to the viewing device

You can get the details on following Link: difference px,em and ex

Shivkant
+1  A: 
  1. Pixels are browser dependent. It is the absolute size that you would see on your screen.
  2. Em are sort of like percentages.Ems is referring to the base text size. The value of 1 em means the same thing as a value of 100 percent. But you can also say it the opposite way: A percentage valueis just an em multiplied by 100.
  3. Points(pt) are what you would want to use on print media.
jpartogi