About em

This is the first in a series of art­icles on what most people refer to as elastic
lay­outs, though I prefer the term pro­por­tional layouts.

What is a em?

The unit that is most com­monly used for elastic lay­outs is the em. The em
is a type­set­ting unit of meas­ure­ment, an em is defined as the width of the
upper­case M in that
font face and point size. With brow­ers that is not quite true. For example,
below are 20 Ms in a 20em wide 1em hide div, with no pad­ding and 1 pixel bor­der.
First in the default font for this site Lucida Grande, the second in Arial
and the third is Times New Roman.

MMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMM

PC users on IE (every­body else will have to trust me or look below) should see that that both the Lucida Grande and Arial do not fill the 20em block, while Times New Roman, the default font of browsers fills the 20em block. It appears that at some stage in the devel­op­ment of browsers some­body decided that 1em = 16 pixels at 100% font size and it will not vary depend­ing on the font face.

PC view

As seen on Win XP in IE6

Setting your em and font size

1em = 16 pixels is going to lead to some rather large text, so the easi­est
way to text down to a man­agable size and avoid a nasty IE bug is to set body
font-size: to a percentage:

per­cent­age   font size
100.1% 16 pixels
 94% 15 pixels
 87.5% 14 pixels
 81% 13 pixels
 75% 12 pixels
 69% 11 pixels
 62.5% 10 pixels
 57%  9 pixels

There is one the­ory that sug­gest using 62.5%, which makes an em = 10 pixels, which makes it easy to cal­cu­late num­bers mul­tiply­ing by ten, unfor­tu­nately it also mean that unless your preffered font size is 10 pixels you have to be care­ful about nest­ing tags.

My view, set the per­cent­age to get the right size for the body font p, td, li etc. and then make use of the cal­cu­lator than comes with every com­puter OS to do the hard cal­cu­la­tions for you.

Line Lengths

There are numer­ous research on the ideal length of line for read­ing, with the res­ult being some­where between 50 and 70 char­ac­ters. Does this mean the best length for read­ing is between 50 and 70 em. The answer is only if the read­ing lots of upper case M and W. Another type­set­ting unit of meas­ure­ment in the en, which is defined as the width of the lowecase n and is usu­ally close 50% of a em, and most char­ac­ters are only are only as wide as a n not a M. That would sug­gest 100 char­ac­ters will occupy 50 em. Lets, have a look at those 20 em wide boxes again

Lorem ipsum dolor sit amet, con­sect­etuer adip­is­cing elit. Duis justo
odio, com­modo vitae, dapibus ali­quam, cursus nec, purus. Praesent neque.
Vivamus vitae enim et massa posuere ves­ti­bu­lum. Ut in nunc. In sit amet
tel­lus et turpis con­sequat ornare.
Lorem ipsum dolor sit amet, con­sect­etuer adip­is­cing elit. Duis justo
odio, com­modo vitae, dapibus ali­quam, cursus nec, purus. Praesent neque.
Vivamus vitae enim et massa posuere ves­ti­bu­lum. Ut in nunc. In sit amet
tel­lus et turpis con­sequat ornare.
Lorem ipsum dolor sit amet, con­sect­etuer adip­is­cing elit. Duis justo
odio, com­modo vitae, dapibus ali­quam, cursus nec, purus. Praesent neque.
Vivamus vitae enim et massa posuere ves­ti­bu­lum. Ut in nunc. In sit amet
tel­lus et turpis con­sequat ornare.

A quick count will see that 20em is close to 40 char­ac­ters, so if you want to make things easy to read line length should be between 25em and 35em. Don’t believe the research, try read­ing this art­icle in:

Russ Weakley’s Ideal line length for con­tent was used as a start­ing point.

9 Responses to “About em”

  1. nick Says:

    Richard Rutter’s How to size text using ems is another art­icle on the sub­ject of ems and the com­ments are as inter­est­ing as the post.

  2. James Says:

    Nice work with the elastic lay­out. Site looks good, will have to check it once in a while.

  3. Gene Falck Says:

    I see vary­ing length sequences of M’s in the first three boxes as I think you
    inten­ded in Moz­illa 1.7 on WinXP pro with SP2. Maybe oth­ers not on IE won’t
    have to take your word for it! Very interesting.

  4. nick Says:

    Ooops I tem­por­ar­ily lost the image from IE6 which shows 20 upper­case Ms in Times New Roman really do equal 20em, at least in IE6. It also works in Fire­fox on a PC as long as the font is set at 100%, but because how this page works with vary­ing the font size, I can not show you here.

  5. Nick Says:

    There where a few posts on the WSG (Web Stand­ards Group) mail­ing list about ems and I received some feed­back regard­ing this About em com­ment­ary, so I did some more invest­ig­at­ing and exper­i­ment­ing see More about em

  6. A Different Opinion » Blog Archive » A little less Um and Ah about Em Says:

    […] http://nickcowie.com/2005/about-em/ […]

  7. germworks.net » Blog Archive » JP2 Designs update Says:

    […] So the ques­tion I have yet to answered is do you use pixels, em or per­cent­age or both??? For JP2 Designs I used per­cenatge, next web­site I may use em like the way CLAG does in his art­cile. Hear is a few art­icles on em. em explained by nick cowie and em explained by clag. It is alot of fid­dling and play­ing around as I myself have spent a few hours just get­ting it look­ing descent. […]

  8. Suhas Dhoke Says:

    Where from we know the default font-size (14px, 16px, etc) of client’s machine ?

  9. nick Says:

    Suhas, unless a cli­ent has changed their default font-size ( and from exper­i­ence 99% of people do not change their default font size) or is using a pre 2000 Mac, their default-font size will be 16px.

    If you want to be sure, there is an art­icle in A List Apart about using javas­cript to detect default font size.

Affiliates

Google
text advertising by
Powered by Reseller Zoom