Type on Screen

Typography Fundamentals

Course 1 ยท Chapter 6 ยท Type on Screen

In Typography Fundamentals 5 you chose two typefaces and gave each a job. Choosing a typeface is one thing; getting it onto a reader's screen is another. A font designed with curves and fine details has to be turned into a few thousand coloured squares, and on the web the font file also has to travel across a network before anyone can see it. This chapter covers both halves: how a screen draws a letter, and how a web page loads and falls back when the font you wanted is late or missing.

What was run, and what was not
The one Python script in this chapter was run on Windows with Python 3.14.0, using only the standard library; the output shown is exactly what it printed. The font file sizes mentioned in the text are rough ballpark figures (check). The CSS snippets were not tested across several browsers, and the font names and file paths in them are invented placeholders.

How a Screen Draws a Letter

On paper, a letter is ink: a printer can place a dot of ink almost anywhere, and modern printers lay down hundreds of dots per inch (check). A screen is a grid of pixels, and each pixel is one fixed square of light. At body-text sizes, a letter such as an "e" may be only seven or eight pixels tall. The thin diagonal and the curve of the bowl simply do not fit neatly into a grid that coarse, so the screen has to decide, pixel by pixel, what to do with the edge of every stroke. Three techniques do that work.

TechniqueWhat it doesWhat you see
RasterisingConverts the outline of each glyph into a grid of pixels at the requested sizeThe basic shape of the letter
Anti-aliasingColours edge pixels in shades between the text and background colours, according to how much of the pixel the stroke coversSmooth edges instead of jagged "stairs"
HintingInstructions inside the font that nudge outlines so stems and heights land on whole pixelsCrisper, more even letters at small sizes

Anti-Aliasing, Made Visible

The easiest way to understand anti-aliasing is to do it yourself. This script draws a slanted stroke (a stand-in for the diagonal of a letter) on a tiny grid, twice. The first drawing switches each pixel fully on or off. The second measures, for every pixel, how much of it the stroke covers by checking a 4 by 4 set of sample points inside it, and picks a darker or lighter character accordingly.

"""Anti-aliasing demo: draw a slanted stroke on a tiny pixel grid, two ways. py aa.py """ W, H = 16, 6 # grid size in pixels SUB = 4 # sub-samples per pixel in each direction SHADES = " .:-=+*#%@" # light to dark def inside(x, y): """The 'letter': a slanted stroke, about 2.2 pixels wide.""" centre = 3 + y * 1.6 return abs(x - centre) < 1.1 def coverage(px, py): hits = 0 for sy in range(SUB): for sx in range(SUB): x = px + (sx + 0.5) / SUB y = py + (sy + 0.5) / SUB hits += inside(x, y) return hits / (SUB * SUB) print("Without anti-aliasing (each pixel fully on or off):") for py in range(H): print("".join("@" if coverage(px, py) >= 0.5 else " " for px in range(W))) print() print("With anti-aliasing (pixel darkness = how much the stroke covers it):") for py in range(H): row = "" for px in range(W): c = coverage(px, py) row += SHADES[round(c * (len(SHADES) - 1))] print(row)
Without anti-aliasing (each pixel fully on or off): @@ @@@ @@ @@@ @@ @@ With anti-aliasing (pixel darkness = how much the stroke covers it): -%#. .*@= :%%: =@*. .#%- -%#.

Look at the first drawing: the stroke zig-zags, and its width wobbles between two and three pixels from row to row. That is the jagged look of text with no anti-aliasing. In the second drawing the same stroke fades in at its edges, so the eye reads one smooth diagonal. Real systems do this with shades of grey, or, with a technique called subpixel rendering, by using the separate red, green and blue parts of each pixel on an LCD screen to triple the horizontal detail (check which systems use it by default; it varies, and it is turned off on some displays).

Hinting in one sentence
Anti-aliasing softens the edges you cannot avoid; hinting reduces how many edges land badly in the first place. A hinted font carries instructions such as "make these two stems exactly one pixel wide" or "round this x-height to a whole pixel". How much hinting matters depends on the operating system and the screen: it was very important on the low-resolution screens of the past, and matters less on today's high-resolution displays (check).

Screen Versus Print

The same typeface can be a delight on paper and tiring on screen, or the other way round. The differences you can control are worth knowing.

QualityPrintScreen
ResolutionVery fine; thin strokes and small serifs surviveCoarser, though high-density ("retina") screens narrow the gap (check)
LightReflected: ink on paperEmitted: the screen glows, so white backgrounds can dazzle
Reader's controlNone: the page is fixedReader can zoom, resize the window and change the system font size
Unit of sizePoints and picas (Typography Fundamentals 3)CSS pixels, rem and em
Fonts guaranteed?Yes: the printer uses what you supplyNo: the reader's device may lack your font

Two practical consequences follow. First, a delicate hairline-weight typeface that looks elegant in a printed brochure can fade away at 14 pixels on a phone, so pick a sturdier weight for body text on screen. Second, because the reader controls the screen and you do not, design for flexibility: size text in rem, so it respects the reader's settings, and never block zooming. A px unit in CSS is not a physical pixel but a reference unit that the browser scales to the display (check), which is why the same CSS looks similar on a standard and a high-density screen.

Light weight, small size

The thin strokes of a light weight lose contrast at small sizes, especially on dim or low-resolution screens.

Regular weight, same size

The thin strokes of a regular weight hold up better at small sizes, especially on dim or low-resolution screens.

Live text: the difference may be subtle on a high-density screen, and your system may substitute another font if it lacks this one.

Web Fonts: Sending a Typeface to the Reader

Until web fonts arrived, a website could only use the fonts already installed on each visitor's device, which is why the pairings in Typography Fundamentals 5 used familiar names such as Georgia and Verdana. A web font is a font file your server sends along with the page, so everyone sees the same typeface. You tell the browser about it with the @font-face rule.

@font-face { font-family: "Orchard Serif"; /* the name you will use in CSS */ src: url("/fonts/orchard-serif-regular.woff2") format("woff2"), url("/fonts/orchard-serif-regular.woff") format("woff"); font-weight: 400; font-style: normal; font-display: swap; /* show fallback text immediately */ } body { font-family: "Orchard Serif", Georgia, "Times New Roman", serif; }

Read the rule as a small catalogue entry. font-family gives the font a name. src lists where to get it, best format first, and the browser downloads the first one it understands. font-weight and font-style say which style this particular file is, so that bold text uses the bold file and not a smeared fake. And font-display decides what the reader sees while the file is on its way, which we come back to below.

Font Formats

FormatWhat it isUse it?
WOFF2A compressed font format made for the web, usually the smallest (check)Yes: the default choice, supported by all current major browsers (check)
WOFFThe earlier compressed web formatOnly as a fallback for old browsers (check whether you still need it)
TTF / OTFThe ordinary desktop font formats; uncompressedRarely on the web: larger files, no advantage
Check the licence first
A font on your own computer is not automatically free to publish on a website. Many fonts have a separate web licence, and some forbid embedding altogether. Open-source and free-to-use font libraries exist (check the licence of each font before using it), and a licence mistake is a legal problem no amount of good typography fixes.

Variable Fonts: Many Styles in One File

A traditional family ships a separate file for each style: regular, italic, bold, bold italic, and so on. Four styles can mean four downloads. A variable font packs a whole range of styles into one file by describing the outlines with axes, sliders that the browser can set to any value. The standard axes are weight (wght), width (wdth), italic (ital), slant (slnt) and optical size (opsz), and a font designer may add custom ones (check the current list).

@font-face { font-family: "Orchard Sans"; src: url("/fonts/orchard-sans-var.woff2") format("woff2"); font-weight: 300 800; /* the range this one file covers */ font-display: swap; } h1 { font-weight: 800; } h2 { font-weight: 650; } /* any value in the range works */ .note { font-variation-settings: "wdth" 85; } /* a lower-level way to set one axis */

The big gain is flexibility: a weight of 650 is as easy as 600 or 700, and a smooth transition between weights becomes possible. The saving in bytes is real when you need several styles, though a variable file is bigger than any single static one, so if you only need regular and bold, two static WOFF2 files can still be smaller (check by comparing the actual files). Not every font is available as a variable font, and the axes it offers differ from one font to the next.

Fallback Stacks and the Loading Moment

A font file can arrive late, or never. The font-family list is called a fallback stack: the browser uses the first family that is available and moves down the list. You met the idea in Typography Fundamentals 5; this is why every stack ends with a generic family such as serif or sans-serif, so that some sensible font always appears.

While a web font downloads, the browser has to choose what to show. font-display controls that choice:

ValueWhile waitingBest for
swapShows fallback text at once, then swaps to the web fontBody text: readable immediately, but the text may visibly change
blockHides the text for a short period, then swapsRarely: invisible text is a poor experience
fallbackA very short hidden period, then fallback, with a limited time to swapA compromise for long text
optionalUses the web font only if it is available almost instantly (check the exact timing)Non-essential decorative fonts

The visible jolt when text swaps fonts is called a layout shift: the fallback and the web font have different widths, so lines re-wrap and the page jumps. You can soften it by choosing a fallback with similar proportions, and CSS offers descriptors such as size-adjust and the ascent-override group that let you tune a local font to match the web font more closely (check browser support).

The typography of waiting
Most readers never see your web font at its best; they see the fallback for a moment, or for ever, on a slow connection. A design that only works with the exact font is fragile. Test your page with the web font switched off and make sure it still looks reasonable.

Performance: Fonts Are Files

Each font file costs download time, and text cannot settle into its final form until the files arrive. A few habits keep that cost down:

  • Use fewer files. Every weight and style is another request. Does the page really need regular, italic, bold and bold italic? (This is the two-family rule from Typography Fundamentals 5 turned into a performance rule.)
  • Prefer WOFF2. It is usually the smallest format (check), so serve it first.
  • Subset. A font may hold thousands of glyphs for dozens of languages. If your page is in English, a Latin-only subset can be much smaller (check; Typography Fundamentals 7 explains why you must not subset away characters your readers actually need).
  • Preload the critical file. A <link rel="preload" as="font" crossorigin> tag tells the browser to fetch the main heading or body font early (check the exact attributes before using it).
  • Consider system fonts for body text. The system font stack, such as system-ui, costs no download at all and looks native on each device.
:root { /* A system stack: zero downloads, a native look on each device */ --font-system: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; /* A web font for personality, with the system stack behind it */ --font-display: "Orchard Serif", Georgia, "Times New Roman", serif; } body { font-family: var(--font-system); } h1, h2 { font-family: var(--font-display); }

This pattern is a popular compromise: the body text, which is most of the page, appears instantly in a system font, and only the headings pay the cost of a web font. If the web font fails, the headings fall back to Georgia and nothing breaks.

Idea in this chapterAn idea you may already know
Anti-aliasingResizing a photo: smooth blended pixels instead of hard blocks
Fallback stackA try/except chain, or an || chain of default values
Subsetting a fontTree-shaking a JavaScript bundle: ship only what is used
Variable fontA function with parameters, in place of many near-identical copies
Font preloadWarming a cache before it is needed
Common mistakes with type on screen
Setting body text in a hairline weight; sizing text in px so readers' settings are ignored; loading six font files for one page; forgetting a generic family at the end of the stack; leaving out font-display so text stays invisible while loading; and only ever testing on your own fast connection with the font already cached.

Hands-On Exercises

Three exercises: a written plan for loading fonts on a real-sounding site, a code task that checks a font budget, and a CSS task that sets up a variable font with a safe fallback. Each has a solution file that opens in a new tab.

Exercise 1

A small bakery wants a website that feels warm and handmade, but many of its visitors will be on phones with slow connections. On paper, write a font-loading plan. Say which text uses a web font and which uses a system font, how many font files you will ship and in which format, which font-display value you choose and why, what your fallback stacks are, and how you will reduce the visual jump when the web font arrives. Name one thing you decided not to load and give the reason.

๐Ÿ“„ View solution
Exercise 2

Write a Python script that holds a list of font files, each with a name, a format (woff2, woff or ttf) and a size in kilobytes. Where the same font is offered in more than one format, keep only the best format (woff2, then woff, then ttf). Print a table of the chosen files with a total, compare the total with a budget, and say how far under or over you are. When over budget, name the largest file as the first one to drop or subset. Run it and show the output.

๐Ÿ“„ View solution
Exercise 3

Write the CSS for a page that uses one variable font file with a weight range of 300 to 800. Include an @font-face rule with font-display, a second @font-face that tunes a local fallback font to match the space of the web font, a custom property holding the full fallback stack, and headings that use at least one in-between weight (such as 650). Add a comment on each part explaining its job, and a short print rule that adjusts the body weight.

๐Ÿ“„ View solution

Chapter 6 Quick Reference

  • Screens draw letters on a pixel grid: rasterising makes the shape, anti-aliasing smooths the edges, hinting nudges outlines onto the grid
  • Screen differs from print: coarser resolution, emitted light, and a reader who can zoom and resize; choose sturdy weights and size in rem
  • @font-face names a web font and lists its files in src, best format first; set font-weight and font-style for each file
  • WOFF2 is the default format for the web (check); TTF and OTF are rarely needed there
  • Variable fonts hold many styles in one file through axes such as wght and wdth; declare the range in font-weight
  • Fallback stacks end with a generic family; font-display: swap shows readable text while the file loads
  • Reduce layout shift with a similar fallback and the size-adjust and override descriptors (check support)
  • Performance: fewer files, WOFF2, subsetting, preload the critical file, or use a system stack for body text
  • Check the licence before putting any font on a website, and test with the web font switched off