Strategies, Tricks, and Best Practices
Similar to layout, when it comes to typography one of the most challenging differences between designing for the web vs. designing for print is the size of the canvas: for print, the dimensions are fixed and known; for the web, the dimensions are forever changing and unknown. Another, equally important difference is the content: for print, the content is fixed and known; for the web, the content can change and could be unknown to the designer. The two mediums are fundamentally different.
So how do you control the typography and set good type for the web? Web designers need to think differently by shifting their mindsets to plan for the unknown when setting type on the web. Web designers can still utilize the core principles of typography (e.g. choosing appropriate type faces and pairings, no hanging punctuation, set limits for line length/measure, etc.), but designers must also be able plan for and adapt to the many different screen sizes that users might interact with their type and the many constraints of the web when it comes to controlling the type (e.g. are my columns too wide? too narrow? can I decrease the leading on small screens and increase it on big screens? how can I control the number of characters per line for each?, how will this text wrap? how can I fix my widows? )
The good news is that there are emerging techniques and strategies that have evolved over the years to help aid web designers and front-end web developers trying to execute strong typography. Below is a work-in-progress collection of known best practices, tips, and techniques specifically for web typography that many web designers and front-end designers have come to embrace over the years.
Tip & Tricks:
Measure: Limit the Number of Characters Per Line
To limit the number of characters per line, consider adding an em-based (relative) max-width to your most commonly used text elements, such as your paragraphs and headings.
See the Pen Horizontal Measure with Max-width (limit the number of characters per line) by kccnma (@kccnma) on CodePen.
p { max-width: 30em; }
or you can use a new-school css unit, such as ch:
p { max-width: 65ch; }
Widows: Fix the Known Instances
To fix and avoid widows, consider replacing the spaces in between the last couple of words to non-breaking spaces ( ).
<p>Place non-breaking spaces between the last couple of words.</p>
Another approach, which is relatively newer (and now has good browser support), is to use text-wrap: pretty;
p { text-wrap: pretty; }
Resize your Text Responsively
To provide an equally enjoyable reading experience on small devices and larger screens, consider resizing your typography to be smaller on small screens (since users tend to hold smaller devices closer to their face) and larger on big screens (since users tend to stand farther away from large monitors and displays). If you are looking for a good article on responsive typography with helpful visuals, be sure to check out IA.Nets Basics of Responsive Typography.
body { font-size: 87.5%; }
@media (min-width: 768px) {
body { font-size: 100%; }
}
@media (min-width: 1250px) {
body { font-size: 112.5%; }
}
When Using Webfonts, Avoid Faux Bold & Italic
When using web fonts, be sure to include all weights and styles for each typeface. For example, look closely at your bold and italics to ensure that the correct font is being used. This is important to avoid the browser rendering faux bold and faux italics.
Exercises:
Try using a typographic scale for your headings and paragraphs
See the Pen Typographic Hierarchy by John Doe (@johndoenma) on CodePen.
Try to design a bespoke type specimen by starting with nothing but unstyled HTML Markup
See the Pen Typography Specimen Test – Incomplete by kccnma (@kccnma) on CodePen.
Note how the browser ignores line breaks.
Here’s an example of a bespoke type specimen
See the Pen Typography Specimen Test – Example #1 by kccnma (@kccnma) on CodePen.
Note the use of Google Fonts.
Experiment with different font pairings by doing a coded type studies
See the Pen Type Pairing Test by kccnma (@kccnma) on CodePen.
See the Pen Type Study: Google Font Pairings by kccnma (@kccnma) on CodePen.
See the Pen Type Set Test by kccnma (@kccnma) on CodePen.
Related Resources and Reading
- Online CDN’s &Sources for Webfonts:
- Resources:
- The Elements of Typographic Style Applied to the Web by Richard Rutter
- Better Web Type by Matej Latin
- Typewolf by Jeremiah Shoaf
- Articles & Blog Posts
- Links to all Codepen examples and other web typography-related links referenced in the video lesson:
- Typographic Scale with line height based on ex units and max width based on ch units
- Baseline Test
- Base
- Typography Specimen Test – Example #2 (Scalable Heading Sizes and Body Line-height)
- Article Type Test – Complete
- Drop Caps
- CSS @font-face Rule
- Type Pairing Test
- Type Set Test
- Type Study: Google Font Pairings
- NMA Adobe Fonts
- Tight Typography Tracking with Overlap Test (Fail)
- Variable Fonts are Awesome (forked from CSS is Awesome)
- Variable Font Test
- Text Effect: Animated Text Reveal via Pseudo Element Masks
- Text Effect: Custom Underlined Text (via svg brush stroke)
- Text Effect: Split Text Revealing/Animating In From a Psuedo Mask
- Text Effect: Letters Popping Out with Drop Shadow (looping)
- Text Effect: Animated Text Stripes using background clip and an animated gradient
- Text Effect: CSS Gooey Text Morphing Animation
- Text Effect: Animated Text-Shadow Colors
- Text Effect: Animated Text-Shadow with Line Pattern [webkit]
- Text Effect: SVG Text with Animated Stroke (Dashes) #1
- Text Effect: SVG Text with Animated Stroke (Dashes) #2
- Text Effect: Retro Text-Shadow Animated
- Scaling Text at Different Sizes Test with fontsize min max and font size clamp
- Vanilla JS Widow Fixer for all Blocks of Text (aka Widow Slayer)
- Image-text replacement techniques
Author Notes
This was written specifically to help aspiring web designers as they aim to:
- Apply best practices of typography in the context of web sites and user interfaces.