How To Size Text in CSS
How To Size Text in CSS
HOME
ARTICLES
EVENTS
TOPICS
WRITE FOR US
How to Size Text in
CSS
by Richard Rutter November 20, 2007Published
in Browsers, CSS, HTML, Layout & Grids, Typography & Web
Fonts
There’s been a welcome resurgence
of interest in web typography over the
past year or so, with
many articles and conference talks off
ering techniques and theory.
Frequently asserted is the notion that
good typography requires accurate
control of font size and line-height.
But this is the web: it’s a special
medium where the reader can have as
much control as the designer—the
implication being that text on the web,
while bending to the designer’s will,
must also be reliably resizable across
browsers and platforms.
96 comments
Share this on
A Book Apart:
Brief books for people who make websites.
An Event Apart:
3 days of design, code, and content for web & UX designers &
devs.
In this article, we
will reconcile the
designer’s
requirement for
accuracy with the
user’s need to
resize text on
demand, arriving
at a best practice
that satisfies
designers anduse
rs and works
across browsers
and platforms.
We’ll reach our
destination by the
traditional
method of trial
and error. With
more than a nod
to Owen
Briggs’s pioneerin
g work of 2002, I
have created a
base case with six
iterations and 161
screenshots.
Follow along,
won’t you?
The test
suite
The content used
for testing
purposes was a
two-column
layout with body
copy on the left
and a sidebar on
the right. Text
was set in Arial to
aid consistency
across operating
systems and
platforms.
The browsers
used for testing
were Safari 2,
Firefox 2 and
Opera 9.5α
running on
Mac OS X Tiger,
along with
Internet Explorer
6 (IE6) and
Internet Explorer
7 (IE7) running
on Windows XP
with ClearType
turned on. Clearly
this is not an
exhaustive list of
browsers,
operating
systems, or
rendering
engines, but it
covers the
majority of users
out there today.
Each operating
system and
browser was run
using its default
settings. Every
iteration was
tested to see how
each browser
rendered text at
smaller, medium,
larger, and largest
sizes, along with
90%, 100%,
110%, and 120%
page zoom levels,
where applicable.
Base case
First it was
necessary to
verify that
browsers
provided a
consistent
baseline from
which to start.
The base
case shows that in
each browser, the
default text size is
consistently 16px
when no styles
are applied (other
than the browser
defaults), and the
text scales fairly
consistently
across the board.
Text size in
pixels –
iteration 1
The default text
size of the base
case is a good
starting point,
but for most
people
(designers,
clients, and their
customers) 16px
is too large for
body text. In our
example, the
body text was
reduced to 14px,
with the sidebar
set at 12px. This
first iteration
does just that,
setting the fonts
in pixels:
.bodytext p {
font-
size:14px;
}.sidenote {
font-
size:12px;
}
The result is that
Safari and Firefox
still resize the
text,
whereas IE6 and
IE7 do not. The
text can be
resized in Opera
and IE7 by using
the page zoom
tool, which
magnifies the
page layout, text
and images
within.
Text size in
ems –
iteration 2
Although browser
market share
differs from site
to site, and
browser share
statistics are
drawn in sand,
it’s safe to say
that IE6 is still
used by many
people. So setting
text in pixels
would leave many
people no means
of resizing it.
There’s also an
argument that
says IE7 users
should be able to
resize text
without being
forced to use the
zoom control.
The next unit to
try for text sizing
is ems. The em is
a true
typographic
unit, recommend
ed by the W3C,
and affords a
precision keywor
ds lack. Working
from a default of
16px, the
following styles
should give the
desired text sizes:
.bodytext p {
font-
size:0.875em;
/* 16x.875=14
*/
}.sidenote {
font-
size:0.75em;
/* 16x0.75=12
*/
Body sized
as
percentage
– iteration 3
A fix to the
exaggerated text
resizing
of IE6 and IE7 is
to size the body
using a
percentage. So
retaining the ems
on our content,
the following
styles were
tested:
body {
font-
size:100%;
}.bodytext p
{
font-
size:0.875em;
}.sidenote {
font-
size:0.75em;
}
The results show
that the
difference
between larger
and smaller
browser settings
in IE6and IE7 is
now less
pronounced,
meaning we now
have all browsers
rendering text at
an identical size
on their medium
setting, and
resizing text
consistently.
Setting line
height in
pixels –
iteration 4
Recent web
typography
articles such as
“Setting Type on
the Web to a
Baseline Grid” (A
List Apart, April
2007) stress that
good typography
requires a vertical
grid, that is to say
a solid vertical
rhythm achieved
with a consistent,
measured line-
height. The key
implication is
that line-height
should be the
same regardless
of the size of the
text (so that line-
height, or the
vertical grid,
remains
consistent,
regardless of font
size).
For our example,
a suitable line-
height is 18px, so
that is added to
the body as
follows:
body {
font-
size:100%;
line-
height:18px;
}.bodytext p
{
font-
size:0.875em;
}.sidenote {
font-
size:0.75em;
Setting line
height in
ems –
iteration 5
When pixels
failed before, we
turned to ems.
Repeating the
logic gives us the
following styles:
body {
font-
size:100%;
line-
height:1.125e
m; /*
16×1.125=18
*/
}.bodytext p
{
font-
size:0.875em;
}.sidenote {
font-
size:0.75em;
The Safari
monospace
problem –
iteration 6
The observant
among you may
have noticed a
wee glitch in the
Safari screenshot
s: the
monospaced font
included in the
body text is
rendered
inconsistently.
For text set in
pixels, Safari
renders the
monospaced font
at the same size
as the
proportional-
width text
surrounding it.
When text is set
in ems, however,
Safari renders
monospace text
much smaller
than the
surrounding text.
The inconsistency
appears to stem
from Safari’s
default text sizes,
which are 16px
for “standard
fonts” and 13px
for “fixed-width
fonts.” Safari 3α
on OS X does not
appear to suffer
from this
problem.
You could decide
that undersized
monospace text
in Safari is
something you
and your readers
can live with, and
as Safari 3 is
included in OS
X Leopard and
the latest update
to Tiger, it will
not be long until
the problem
pretty much
disappears. For
the nervous
control freak who
can’t wait, an
alternative fix is
to send text sized
in pixels to Safari.
The following
code appends
a downlevel-
revealed
conditional
comment to our
styles, so that
pixels are sent to
all browsers
except IE6 and IE
7 (note the [if
!IE] syntax,
instructing
IE/Win to ignore
the markup that
follows).
<style
type="text/cs
s">
body {
font-
size:100%;
line-
height:1.125e
m;
}.bodytext p
{
font-
size:0.875em;
}.sidenote {
font-
size:0.75em;
</style><!--
[if !IE]>--
><style
type="text/cs
s">
body {
font-
size:16px;
</style><!--
<[endif]-->
About the
Author
Richard Rutter
Richard Rutter is a co-founder and user experience consultant
at Clearleft, a strategic design studio based in Brighton, UK.
Richard has been solving clients’ problems through digital design
for over two decades, but is probably best known as a self-
appointed web typography evangelist. In 2017 he published his
long-awaited book, Web Typography. Richard occasionally blogs
on a site called Clagnut and can be found @clagnut.
96 Reader Comments
1.
2.
EMBED
3.
4.
EMBED
5.
EMBED
6.
EMBED
7.
EMBED
8.
EMBED
9.
10.
EMBED
11.
EMBED
12.
EMBED
13.
EMBED
14.
EMBED
15.
EMBED
16.
EMBED
17.
EMBED
18.
EMBED
19.
EMBED
20.
EMBED
21.
EMBED
22.
EMBED
23.
EMBED
24.
25.
EMBED
26.
EMBED
27.
EMBED
28.
EMBED
29.
EMBED
30.
EMBED
31.
EMBED
32.
EMBED
33.
EMBED
34.
EMBED
35.
EMBED
36.
EMBED
37.
EMBED
38.
Jonathan Kemp 7:59 pm on November 21, 2007
On the setup I use everyday, there IS a difference in font sizes
between Mac and PC when they are both set to the defaults. On
my PC, which sits right next to my Mac, the fonts are bigger than
they are on my Mac. So I do not get that the fonts are the same
size. Does anyone else experience this or am I the only one?
In addition, I would also like to know why you can’t use
percentages to solve this problem. It seems to work for me.
I did like the article though.
EMBED
39.
EMBED
40.
EMBED
41.
42.
EMBED
43.
EMBED
44.
EMBED
45.
EMBED
46.
EMBED
47.
EMBED
48.
EMBED
49.
50.
EMBED
51.
Miriam Richardson 11:29 am on November 23,
2007
This is a great article, thank you! I have been feeling the need for
an update on Owen Briggs work, and it is fantastic someone has
done that work for us.
With an old PC screen sitting beside my clean, high resolution
mac-connected-monitor, the size differences in IE have been
irritating me for a while. The old monitor seems to have large
pixels, so that everything looks clunky, and it is hard to know
what is the monitor, what is a PC-talking-to-a screen issue, and
what is a browser issue.
So thanks for some hard facts/screen shots and a new formula.
All I have to do now is get used to figuring the maths with nested
ems. And decide where I stand on the line-height issue.
EMBED
52.
53.
EMBED
54.
EMBED
55.
EMBED
56.
cristobal castro 4:10 am on November 25, 2007
the funny thing is that only one person talked about the difference
across browser’s platform, the truth is this:
safari mac and safari pc = no changes in font sizes
firefox mac and firefox pc = big changes in font sizing
conclusion:
safari most consistent browser across pc/mac platform.
EMBED
57.
EMBED
58.
EMBED
59.
EMBED
60.
EMBED
61.
EMBED
62.
EMBED
63.
EMBED
64.
EMBED
65.
EMBED
66.
EMBED
67.
EMBED
68.
EMBED
69.
EMBED
70.
EMBED
71.
Chris McKee 4:54 am on January 04, 2008
Fantastic article, but on thing really stuck in my head as I looked
thorough the countless screen-shot examples (cant beat pictures),
the difference that ClearType makes with browser rendering in
comparison to the mac fat’n'furry soft rendering.
I get that its a personal preference, but wouldn’t it be great if
Apple and MS could just agree that fonts should display as they
were intended to by their designers.
EMBED
72.
EMBED
73.
EMBED
74.
Felix Miata 5:18 am on March 07, 2008
@article base case - "For most people (designers, clients, and
their customers) 16px is too large for body text" is a rude and
unsupported assertion. While empirically it can be said it is quite
evidently true of web designers, the same cannot be said of the
other two groups. The "size" of 16px has been creeping down for
over a decade as the average PPI has been creeping up. While it
may well have been true over a decade ago that most people
agreed the defaults were too large, there is no published evidence
anywhere I have found to support that assertion against the
average current environment. OTOH, there is at least some
published support in contradiction
“http://www.useit.com/alertbox/designmistakes.html”:http://w
ww.useit.com/alertbox/designmistakes.html and recommending
that user default size be respected
“http://www.w3.org/QA/Tips/font-
size”:http://www.w3.org/QA/Tips/font-size to be found on other
than my own web site.
Konqueror defaults to a pt size that is less than 16px when the
DPI is 96. All IE browsers default to 12pt, not 16px. 16px only
appears to be its default as a consequence of the a default M$
system setting of 96 DPI. Use of other than 96 is common on
recent and current laptops (which, by the way, have been
outselling desktops for several years), which typically have a
considerably higher than average PPI and need OEM correction
to avoid illegible text on their already small displays.
Manufacturers have made 120 DPI a virtual default for laptops.
The result is IE and other browsers whose defaults are not set in
px give users who have not made further corrections 20px @ 12pt
instead of 16.
@article&more; (Richard R, David L, others) - Line-height set
other than unitless is a bad habit. That only unitless carries down
the cascade as a factor rather than as a previously computed value
is a good thing. It means when zoom or minimum font size are
employed by the user’s agent to turn your mousetype into
otherwise legible text that that text is not constrained to a space
into which it cannot fit without overlapping the text above and
below it. See “http://mrm.no-ip.com/auth/line-height-
inherit.html”:http://mrm.no-ip.com/auth/line-height-
inherit.html to understand the problem.
@1 (Kari P) - IE em sizing problems are complicated. As
answered earlier, setting a % size on body eliminates IE’s basic
compounding problem. What hasn’t been mentioned is that the
various browsers round differently. That means the starting point
can be different right off the bat, but as they cascade and
additional sizes are added, the rounding differences also
compound. Take a look at “http://mrm.no-
ip.com/auth/Font/font-rounding.html”:http://mrm.no-
ip.com/auth/Font/font-rounding.html for more detail via a
testcase.
@5+ (James S, more) - No one here yet mentioned a not
inconsequential result often encountered on pages using the
Clagnut/62.5% method. 62.5% is really convenient only for
designers who think they need to size things in relation to this
variable and unknown size thing called a px. Invariably these
designers prefer text in their work to be a smaller size than
average people are comfortable with. For defense against this
rude designer behavior, modern user agent makers include
functions like text zoom, page zoom, and minimum font size.
When text zoom and/or minimum size are applied by user agents
based upon the Gecko rendering engine, the ostensibly intended
effect is multiplied in a manner similar to IE’s font sizing of ems
that aren’t applied against an ancestral % size. The effect is truly
overlarge text (based upon the visitor’s preferred size), often
producing overlapping and/or hidden (inaccessible content).
“http://mrm.no-
ip.com/SS/Clagnut/eonsSS.html”:http://mrm.no-
ip.com/SS/Clagnut/eonsSS.html demonstrates the problem with
screenshots, but you can easily see for yourself by setting equally
default size and minimum size to a size significantly more than
16px and then visiting a 62.5% site, such as
“clearleft.com”:http://www.clearleft.com.
@26 (Voyou D) - Please stop repeating the mantra. The defaults
stopped being "big" years ago. For most web browsers the default
size measured in px has not changed for at least 12 years, and
probably much longer. Because of the decrease in average PPI
over the years, the apparent default size has been decreasing. To
the rest of what you wrote, well said.
@32 (Adrian D) - It isn’t a little rude, it’s a lot rude.
@37 (Jason S M) - Not only does changing your browser defaults
not not make perfect sense, you’re derelict in your testing
thoroughness to not be constantly changing them to emulate the
wide range of possible user conditions. There are too many
variables in user environments to assume that users have one
resembling your own, regardless what the system and browser
settings were when you got your own hardware. Assuming any
user setting to be wrong and in need of arbitrary adjustment by
someone with less than 100% of the situational facts is nothing
short of rude.
@39 (Stephen D) - Web browsers are user agents, not web page
author agents. Those incapable of accommodating user wishes
and needs are broken. It doesn’t matter what your design requires
or the CSS specs seem to say. If I can’t read it, it’s worthless.
@48 (Dusan S) - Modern open source operating systems can and
do detect display DPI, thus rendering text on screen sized in pt
exactly the same size as when printed. The problem is that screen
resolution falls short of print resolution, while the average
distance between text and user’s eyes is considerably greater for
screens compared to books, magazines and newspapers. Text on
screen usually needs to be physically bigger than printed text in
order to be equally comfortable to read, or even legible. Firefox
for Linux and Mac do allow a different assumed DPI, but there is
no UI for changing it. Type about:prefs in the urlbar, then dpi in
the search box to find the pref.
@55 (Andrej T) - Decimals in font size rules are ignored by IE.
62.5% is treated by it as 62.00%.
@62 (Kendall C) - If you’re in the design business, you’ll probably
find yourself back on ALA often. Make yourself a user stylesheet
that applies exclusively to it via Gecko’s @-moz-document facility
and you won’t know about its tiny text until it gets a CSS overhaul
that breaks your overrides.
@68 (Mason B) - If you’re using a decent modern display better
than the median, you have enough PPI that small differences in
font sizes should produce no apparent qualitative differences. I
don’t ever find smaller than my default fonts easier to read,
regardless how many px it took to render them, or how good they
"look". Indeed, if you render a font at "font-size: 80%" that was
18px in height, what you actually get is a font 64% in size. CSS
"size" is only nominal, not real. Real size is a function of both
height and width. A 16px character contains around 128 discrete
px, measuring around 8px wide by 16px tall. A character box
exactly 80% of 18px high would be 6.4px wide by 12.8px tall,
providing about 82 discrete px.
Be part of the solution to the problem rather than part of the
problem. Accept that 100% of the default size is best. Personal
computers are intended to be personalized. Assuming they have
been is the right thing to do, no matter how few have actually had
it done. Just because web designers all think browser makers are
morons is no justification for assuming smaller is better for
anyone other than yourself. If the defaults are too big for you,
personalize your own PC, not mine.
EMBED
75.
EMBED
76.
77.
EMBED
78.
EMBED
79.
EMBED
80.
EMBED
81.
EMBED
82.
EMBED
83.
EMBED
84.
EMBED
85.
Pieter Beulque 4:53 pm on November 26, 2008
There’s also a easy trick for this one:
An em is 16px.
10px equals 62.5% of 16px, or an em.
So if you put the font-size for the body element to 62.5%, it’s easy
to calculate the other ones.
E.g. if you want 12px font-size, you just put in 1.2em. Because 1.2
* 10 = 12.
Regards,
Pieter
EMBED
86.
EMBED
87.
EMBED
88.
EMBED
89.
EMBED
90.
EMBED
91.
EMBED
92.
EMBED
93.
EMBED
94.
EMBED
95.
EMBED
96.
EMBED
Orchestrating Experiences
by Chris Risdon, Patrick Quattlebaum
In this excerpt from Orchestrating Experiences, you’ll learn about
weaving touchpoints together into a seamless experience.
· June 7, 2018
User Experience
About
Authors
Masthead
Style Guide
Contact
Sponsorships
A BOOK APART
Brief books for people who design, write, and code.
Bundle books and save!
Shop now
AN EVENT APART
Three days of design, code, and content for people who make websites.
See this year’s schedule