tags:

views:

66

answers:

3

I was reading now about how it’s a good practice to set the font on <body> to 62.5%, so that later you can use the divide-by-10 conversion from pixel units.

But I was wondering: why not set <body> to 6.25%? Then you can use the same dimensions for em units as for pixel units, assuming the default browser font size is 16 pixels.

E.g.

body {
    font-size: 6.25%; /* 1px */
}

p {
    font-size: 12em; /* 12px */
}
+2  A: 

If you are doing this, you will have to make sure you resize every font on the page. If you miss anything, it will be tiny by default (1px).

Resizing every font may be more daunting then you imagine, because when you use relative font sizes, you have to be very specific.

Samuel Cole
+5  A: 

Two issues.

  1. I seem to remember that if you set your initial font size quite small using a relative unit like ems, if the user resizes the text Internet Explorer, the font size will change quite a lot between the settings.

    It’s an odd phenomenon, and I’m not sure if it still occurs in IE, nor if you’re worried about users in IE who change the font size.

  2. You’re potentially condemning yourself to re-setting the font size every time you nest elements.

    An answer I wrote to another question tries its best to explain this, but in short, if you’re doing your font sizes in ems, you’re better off using font-size as little as possible, rather than making it ever-so-slightly easier to use font-size when you do.

    For example: say you want all <li>s on the site to use a font size of 12 pixels.

    li {
        font-size: 12em;/* 12px */
    }
    

    If you then use the following HTML:

    <ul>
        <li>
            <ul>
                <li>
                ...
    

    Then you need to do this:

    li li {
        font-size: .083em;/* 12px */
    }
    

    Otherwise the inner <li>s will be 12 pixels * 12 pixels = 144 pixels!

    Ems aren’t pixels. Ems refer to a percentage of the nearest ancestor’s font size, whereas pixels refer to actual pixels. In my opinion, trying to turn ems into pixels is more confusing than the alternative. You’re better off setting <body> to the most commonly used font size on the site, only changing from that when you need to, and putting the intended size in pixels in a comment after your em-based declaration. (That way, it’s easier to tell later if you’ve got something wrong.)

    (Of course, the only reason we avoid pixels is because IE doesn’t change the size of text sized in pixels when the user changes the font size in the browser. If you’re not worried about that, then just use pixels.)

Paul D. Waite
+3  A: 

Short answer: Don't do this. Use px to set font sizes. If you need a bigger font, use a larger number of px.

Long answer:
The idea behind setting the base font is make it obvious how big a ems and exs are. If your base font size is 10px, then 1.0em is 10px, 1.2em is 12px, etc. It seems simple enough. The idea breaks down as soon as a container changes the font size from the base. If you're in a div with the font size set to 20px, then all the sudden 1em is twice as big as it used to be.

It gets worse. People started suggesting that 62.5% should be used rather than 10px.
(Note that 16 * 0.625 = 10). This was suggested because specifying a percentage for font size is a workaround for an issue with old versions of Internet Explorer. The end user couldn't "zoom in" unless you used a percentage.

However, % (when applied as the default font) is an absolute unit. It may seem like a relative unit, but here, it's a percentage of the user agent's default font size, and font sizes are specified in points. This introduces a subtle and incorrect assumption about the user agent, namely that the screen resolution is 96 dpi. This assumption often results in text which looks like this:

Hey check me out, I'm too small to read!

To sum up:
Don't use hacks for old versions of IE (4 years is plenty of time to maintain backward compatibility; IE7 is four years old this month).

Don't make assumptions about your user agent's resolution, and don't set the body font size to a percentage.

If you need more precise typographical control, use a CSS framework like Baseline.

Seth
very strange because i have read that i should use ems as a unit instead of px, mainly so that the change font size works in Internet explorer.
Karim
The main takeaway from my answer should be "don't do special things for IE, it doesn't need them anymore." Target the standards, and all is well.
Seth
It’s debatable whether IE needs this any more. If you size text using `px`, as of version 8 IE users still won’t be able to resize the text. They can zoom instead, but zooming isn’t the same as increasing the text size. Whether this is important to you depends on your audience. It may well be that it’s not worth catering to the people on IE who want to resize text, but I don’t think you can sensibly have a blanket rule about it.
Paul D. Waite
@Paul, you are correct, but doing this compromises the experience for every other browser (and is much harder for a web designer to implement correctly). If all the user wants to do is make it bigger (an accessibility issue), they can make a custom style sheet, use large fonts in Windows, or even reduce the screen resolution. I would imagine that `Ctrl +` is a more likely action.
Seth
@Seth: oh, the whole `6.25%` thing has problems, sure. But I don’t think using ems in general causes issues in other browsers.
Paul D. Waite
Sorry, should have been more specific; using `body { font-size: 62.5% }` causes issues. Using `6.25%` surely causes issues!
Seth