What is the difference between px
, em
and ex
? And when you define font-size in CSS, do you use px
, pt
or
em : The em
is a scalable unit that is used in web document media. An em is equal to the current font-size, for instance, if the font-size of the document is 12pt
, 1em
is equal to 12pt
.
px : Pixels are fixed-size units that are used in screen media (i.e. to be read on the computer screen). One pixel is equal to one dot on the computer screen (the smallest division of your screen’s resolution).
pt : Points are traditionally used in print media (anything that is to be printed on paper, etc.). One point is equal to 1/72 of an inch. Points are much like pixels, in that they are fixed-size units and cannot scale in size.