Exercise 3 solution: web font CSS for a variable font with a safe fallback ========================================================================== A sample answer. "Orchard Sans" is an invented font name and the file paths are placeholders; the CSS was not tested in several browsers. /* 1. The web font: one variable file covering weights 300 to 800. */ @font-face { font-family: "Orchard Sans"; src: url("/fonts/orchard-sans-var.woff2") format("woff2"); font-weight: 300 800; /* the range the file supports: lets font-weight use any value */ font-style: normal; font-display: swap; /* show fallback text at once, swap when the font arrives */ } /* 2. A tuned fallback: a local font adjusted to take up about the same space, so the swap does not make the page jump. Tune the percentages by testing (check). */ @font-face { font-family: "Orchard Sans Fallback"; src: local("Arial"); size-adjust: 104%; ascent-override: 92%; descent-override: 24%; line-gap-override: 0%; } :root { /* the web font first, then the tuned fallback, then real system fonts, then a generic */ --font-main: "Orchard Sans", "Orchard Sans Fallback", system-ui, "Segoe UI", Arial, sans-serif; } body { font-family: var(--font-main); font-weight: 400; line-height: 1.6; } h1 { font-weight: 800; } h2 { font-weight: 650; } /* an in-between weight only a variable font can give */ .lead { font-weight: 300; } /* 3. Print: keep the same family, but make sure the weights are not too light on paper. */ @media print { body { font-weight: 450; } } Why each part is there ---------------------- - font-weight: 300 800 in @font-face tells the browser the file is variable on the weight axis; without the range, the browser may fake weights it thinks are missing. - The fallback @font-face with size-adjust and the override descriptors makes the stand-in font behave like the real one while it is loading. - The stack ends with system-ui and a generic family so some sensible font is always used if the file fails. - 650 for h2 shows the benefit of a variable font: one file, any weight in the range, where a static family would need a separate file for each weight.