Em units versus ex units
This article addresses the use of relative "em" and "ex" units in CSS, which can potentially cause rendering problems due to pixel rounding errors. Read about em and ex values in the CSS2 specification.
The problem occurs when a relative value doesn't equal a whole pixel value. In that case, the Gecko layout engine can sometimes incorrectly add or remove a pixel from an object's size due to rounding errors. Rounding errors can occur in circumstances not covered by this article as well. A lot of information on the topic is available in Mozilla's Bugzilla bug-tracking database .
Though the problem can be avoided altogether by using absolute pixel units to define the size of your objects, sometimes relative units are necessary. Therefore, relative values must be intelligently used to avoid the problem. At "normal" font sizes (the defaults on Windows systems, and possibly Linux and others), 1 em is 10.06667 pixels, and 1 ex is 6 pixels. Therefore, ex units are recommended over em units, since they are more easily converted into evenly-rounding pixel values. Though some relative values may scale cleanly to different font sizes, there is, once again, potential for rounding errors. Regardless, it's still safer and easier to calculate whole pixel values using ex units.
- The DOM Inspector can be used to find the calculated pixel value of objects sized using relative units .
In the following table, notice how much easier it is to get evenly-rounded pixels using exes. Most whole pixel values fall on common fractions of ex units (1/2, 1/3, 1/6). By contrast, a single em unit rounds to 10.06667 pixels, and the first whole pixel value is obtained at 3 ems. Additionally, odd fractions are needed to reach useful whole pixel values when using ems. With exes, it's simply a matter of dividing by six.