cssbrowser

Is sizing fonts using "em" still relevant?


Those of you who use em when sizing fonts will know that they can be a headache when dealing with nested elements, and having to make the px -> em calculations (to ensure your design interpretation is correct @ 100%) consumes extra time.

With these (admittedly minor) issues in mind, and given the recent progress the major browsers have made towards natively dealing with accessibility issues such as page scaling / zooming, is using em to size fonts still considered worthwhile? *

*legacy browser (IE6) support excluded.


Solution

  • Do not specify the font-size in absolute length units for screen stylesheets. They render inconsistently across platforms and can't be resized by the User Agent (e.g browser). Keep the usage of such units for styling on media with fixed and known physical properties (e.g print)

    If you will use this method, no need to calculate

    You can set the font-size of the body to 62.5%(that is 62.5% of the default of 16px), which equates to 10px, or 0.625EMs. Now you can set your font-size in EMs with an easy to remember conversion, divide the px by 10.

    * 12px = 1.2EMs
    * 13px = 1.3EMs
    * 16px = 1.6EMs
    * 8px = 0.8EMs
    * etc…
    

    This makes everything SUPER easy to remember and eliminates the need for conversion tables. Of course, you will still need to use a conversion table for nested elements when using EMs, if you are not being specific in your CSS, which is a whole separate issue.

    But 76% is much better and you can use this to calculate http://pxtoem.com/

    Yes it's still relevant:

    IE6 is still widely used and is unable to resize the fonts defined in px. => Usability issues. That alone is a no-no.

    and

    IE 7 and 8 don't resize text sized with pixels either, actually. They do have page zoom, but some people prefer to incease text size only.

    Here's a summary of what's good and bad about font sizing in general.

    Font size in css http://easycaptures.com/fs/uploaded/213/2470522253.png

    I personally like ems. Others, like Chris Coyier over at CSS-Tricks.com likes pixels. (Chris has an excellent article on the different font units).

    It really comes down to personal preference.

    Almost similar or related questions on SO

    Should we still use em and % for defining the font-size of the website elements?

    Is there really any point to using relative font sizing in CSS?

    Why em instead of px?

    Font size in CSS - % or em?

    CSS font size: relative vs. absolute values. Which to use?

    Problem with EM

    Using relative instead of fixed size in CSS

    Helpful online tool for px to em

    http://pxtoem.com/

    http://riddle.pl/emcalc/

    http://convert-to.com/pixels-px-to-em-conversion.html

    Convert entire site from px to em (This tool is still in development)

    http://converter.elementagency.com/

    EM Calculator AIR application (will work on all os)

    http://jameswhittaker.com/journal/em-based-layouts-vertical-rhythm-calculator/

    http://jameswhittaker.com/projects/apps/em-calculator-air-application/

    Windows apps

    http://www.thebrightlines.com/2009/11/16/pixem-pixel-to-em-converter/

    http://www.storkas.com/Projects.aspx(go at bottom)

    Pixels to Ems Conversion Table for CSS

    http://jontangerine.com/silo/css/pixels-to-ems/

    http://reeddesign.co.uk/test/points-pixels.html

    emchart

    http://aloestudios.com/tools/emchart/

    http://aloestudios.com/code/emchart/

    Some more articles on this issue

    http://www.d.umn.edu/itss/support/Training/Online/webdesign/type.html