16. CSS Typography - Design for web content (Presentation) Author Oliver Reichenstein
16. CSS Typography - Design for web content (Presentation) Author Oliver Reichenstein
Typefaces are often composed of a number of fonts that define variations in the design and these
are often referred to as a font family. For example, Garamond Regular, Garamond Bold and
Garamond Italic are all fonts and are part of the wider Garamond font family.
Clarity
Arial
Personality
Trebuchet MS
Typography has many purposes but clarity (readability) and personality are two of the
most important. Notice that the two fonts used above are subtly different and this makes a
big difference to the way they appear to the reader.
Typography and typefaces
Typography is not just about choosing the correct typeface for a
particular design, it’s about how that typeface is used:
Size and colour
Line height
Line length (measure)
Letter and word spacing
Use of upper/lower case
General composition, use of whitespace, hierarchy and
vertical rhythm etc.
CSS gives us control of all these variables
Design for web content
Typography in CSS
Web Typography has changed...
• In the past, web designers were restricted to using only those
fonts that were installed on the client computer.
• This limited set of fonts were described as “web safe” or “system”
fonts.
• Modern browsers now support the CSS3 “@font-face” feature,
which enables designers to use just about any font.
• Fonts can be served from the web server or (more usually) from a
font service such as Google Fonts.
https://websitesetup.org/web-safe-fonts-html-css/
Open Source fonts are free
• Fonts with an open source
license may be used for free.
• Some services, such as Google
Fonts, (established in 2010)
provide an easy way to use open
source fonts.
• Font embedding is now well
established on the web and older
browsers are becoming rare.
https://fonts.google.com/
Web font services
• There are several services that provide and/or serve fonts.
• Some are free and others have varying payment models.
• The most popular are shown below:
Adobe Fonts (formerly Typekit): Google Fonts: Free and self-serve using a
Pay for and serve Free and serve provider like Font Squirrel
Variable Fonts
Variable fonts are the next big
typographic innovation on the
web. They have a number of
benefits over traditional “fixed”
fonts. They may be varied along
one or more defined “axes” e.g.
width or weight and can be used
to define a number of typographic
variants from within the same
font file, thus saving bandwidth
and server resources. See the
links on the left to learn about
them now and keep ahead of the
Richard Rutter: Getting started with variable fonts
MDN: Variable fonts guide
pack! Also, take a look at the
Google: Introduction to variable fonts on the web Recursive font project to get an
Can I Use (browser support) idea of what to expect in the near
Variable Fonts (examples)
future.
Design for web content
A Serif Font
reading small printed body text
such as newsprint.
Cambria
A Sans-Serif Font
Calibri
On the web, serif fonts don’t
render well on low resolution
screens and so the sans-serif fonts
are more commonly used for body
text – a reversal of the traditional
printed use*.
*The advent of high resolution or “retina” displays is changing this.
Print/Online Comparison
Sans-serif
heading Serif heading
Sans-serif
body text
Screen Fonts
Georgia x-height
counter
Verdana x-height
Fonts designed specifically for the screen tend to have larger x-heights. This
results in more open “counters”, making them more easily rendered and
therefore more readable. Georgia and Verdana are good examples of this and
are commonly used in combination on websites.
Design for web content
CHOOSING TYPEFACES
System typeface combinations
Verdana body text with Georgia
headings.
https://practicaltypography.com/what-is-good-typography.html
How many typefaces should I use?
You’d have to make a pretty good case for using more than 2.
One for headings, one for body
Typically, one typeface is used for headings and
another used for body text. This creates contrast
between the two and makes the document easier to
read. However, contrast can also be created within a
single typeface using font size, weight and colour.
https://fonts.google.com/specimen/Roboto
Working with CSS inheritance
If your design uses just two fonts, one for body text (paragraphs, lists etc.) and one for headings, you can
use CSS inheritance (the font-family property is inherited) to style all text in your site using just two
declarations:
This works because setting font-family on the body means that every element within the body will inherit
that value (including headings). We then add a rule below the body rule, which overrides the inherited
value for all the headings. Now, every element will be displayed using Calibri except the headings, which
will be displayed using Georgia.
https://developer.mozilla.org/en-US/docs/Web/CSS/inheritance
Design for web content
Distracting “rivers”
p {
text-align: center;
}
Line height is another characteristic that should be used with care for many
fonts in most contexts, the default value works just fine but it's worth
experimenting to see if you can optimise readability.
body {
line-height: 1.1;
}
Measure
Measure: In typography,
“measure” refers to the line length.
We can control this in CSS using
the max-width property on the
containing element, often <main>.
p + p {
margin-top: 2.2em;
}
Vertical rhythm
https://css-tricks.com/css-font-size/
Additional typographic units
• CSS3 introduces some useful new typographic units (rem, ch, vw,
vh and vm).
• The new REM (Root EM) unit may be the most useful for
typography.
• Because the EM unit is relative to its parent element size, it can
be unpredictable or hard to calculate (or both!).
• REM solves this by being relative to the root element <html>, so
the same value can be applied at different levels of the DOM with
the same result.
• See CSS values and units for a complete description.
https://generatedcontent.org/post/11933972962/css3values
The EM has it!
In practice, most designers will use EM units for typography because, despite
the apparent complexity, they work relative to the content context, which
means that content will scale proportionally to its context (usually the parent
element). This is helpful for responsive web design. Many designers will also use
EM units when sizing typographic-related elements such as padding and
margin. This allows whitespace to scale with type.
On Web Typography by Jason Santa Maria is a good place to start. It’s a slim
volume and easy to read – highly recommended.
Learning more