Click here to Skip to main content
15,881,882 members
Articles / Web Development / HTML

CSS and Font Sizes

Rate me:
Please Sign up or sign in to vote.
4.93/5 (7 votes)
28 Sep 2002CPOL4 min read 96.4K   53   10
Does your site have problems with font sizes across platforms or for the vision-impared? the EM unit delivers salvation.


It happens time and again. A graphic designer makes his or her cool new layout, complete with font sizes tweaked to perfection. This designer then tries to change the font size in their browser, and, much to his or her dismay, things break. Carefully sized tables overflow, things look different, and generally this designer curses the font-size change feature.

One solution to this problem is to fix the font sizes so that browsers cannot change them. The advantage of this approach is that it appears to solve the problem, and the layout remains static, even when that nasty font-change feature is used. The designs are protected from the user, who simply does not know good design when he sees it!

What's the Problem?

In terms of HTML and the Web, fixing the fonts this way is a hack. It is an inelegant solution to the problem, and that's not all. This method is disenfranchising a vast swath of potential customers/visitors. The designer is locking out platforms with different default type-rendering systems, like the Mac, and is of course interfering with a disabled visitor's ability to read at a comfortable text size. High-resolution-using visitors often want to dedicate more pixels to the rendering of fonts, but cannot because the designer didn't think anyone would ever want his pristine design to change. This designer has instead locked such users into font sizes measuring just a millimeter or two when the font is at 7pt and the display at 1600x1200 or higher. Clearly, this should be addressed.

So What is the Real Answer, Then?

Example Area
Note that everything in this box scales when you change the font size. The border, the image, and all the text. Browsers can choose the font size they prefer, and the content of the box continues to look almost exactly the same.

A better solution is to use the EM unit in the CSS specification, which is well-supported by most browsers for both positioning and sizing.

EMs are always supposed to be the same relative size, as they are defined as about the width of the letter 'm' in the current font. The current font is always the font used by the parent object in the HTML DOM, or the default font size if none is specified. If you use the default font size, then when the user changes the font size in the browser, all objects defined via EMs are scaled in an exactly proportional way, since your font change command causes the size of the letter 'm' in the document's default font to change. You can define any HTML element in terms of EM via CSS.

6 X 3 em
40 X 20 pt
1.2 X 0.6 cm

So what does this solve? Well, if designers embrace variable font sizing on the web, not only will their design be more robust, it will survive the transition between platforms and resolutions much more successfully. Once your page uses this method, your visitors will no longer be frustrated by fixed font sizes, paving the way for a more flexible and useable web for all of us.

What's the Catch?

EMs are - as you will recall - defined as the width of the letter 'm' in the parent object's font. The parent object may be defined in terms of points, pixels, or some other unchangeable unit, and so most of the power of EM is lost. It just becomes a fancy way of saying 'make this font 1.5 times bigger'. This causes things to act strangely, especially since width:1em will use the document default font, whereas font-size:1em will use the 'parent object font' method. This means you can't have perfect scaling of objects, like in PDF, and things quickly get out of control if you are not careful.

What is needed for PDF-like scaling is a global EM-like unit which is only resized by the user via the browsers font size commands, and not affected by the parent object. With this unit, we could build a page that would reflow with browser width like HTML, but which could scale depending on user preference. Images and other objects would all resize perfectly, and a printout would appear perfect as well.


So what should we do until we get this 'PDF-like' scaling? Either we can use fixed-size fonts as most do today. These fixed-size pages definitely appear as the designer intended, but is that style of page design appropriate given the current state of the Web? Hopefully, you will agree that a good design should complement the medium used to convey it, and not attempt to fight it with size-constraining tricks and other carefully crafted hacks.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Web Developer
Canada Canada
I am currently a student at the University of Alberta
after working over two years as a programmer for a small company.

  • Software Developer
  • Graphic Designer
  • Student

Comments and Discussions

QuestionInformative post [modified] Pin
gggmarketing10-Sep-11 3:22
gggmarketing10-Sep-11 3:22 
GeneralProblem when downloading Pin
papa216-May-10 7:08
papa216-May-10 7:08 
GeneralBrowser compatibility Pin
Bojan Sala13-May-09 21:52
professionalBojan Sala13-May-09 21:52 
Hi all, I want to note that scaling only really works on mozilla-based browsers. Other browsers only have the feature but it's in many cases useless as it either doesn't work at all (safari) or makes the site hard or impossible to read (IE). Firefox is so far able to resize even the most stubborn of sites, along with all of their graphical content (with anti aliasing too) leaving site layout almost untouched.

So, for all those who like BIG, FF is the best according to my testing.

Sadly, for developers - making zooming to work with all browsers involves too much of a design sacrifice which makes the site ultimately unappealing compared to competition. This problem is especially present with smaller sites.
GeneralThanks Pin
Ahmad.Nour23-Nov-08 0:53
Ahmad.Nour23-Nov-08 0:53 
GeneralCheck out YUI Fonts Pin
P.J. Tezza14-Sep-07 15:38
P.J. Tezza14-Sep-07 15:38 
Generalgreat job!! Pin
Lubna_047-Dec-06 0:43
Lubna_047-Dec-06 0:43 
GeneralAmazing how many websites loose business because of this Pin
owen65432124-Sep-06 9:17
owen65432124-Sep-06 9:17 
GeneralExample Area Pin
Christopher Lord29-Sep-02 7:45
Christopher Lord29-Sep-02 7:45 
GeneralRe: Example Area Pin
Shog930-Sep-02 13:51
sitebuilderShog930-Sep-02 13:51 
GeneralNice one Pin
Paul Watson29-Sep-02 2:31
sitebuilderPaul Watson29-Sep-02 2:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.