HTML & CSSEasy
What are font properties?
Font properties control typography: font-family (which typeface, with fallbacks), font-size, font-weight, font-style, line-height, and related properties like font-variant and font-feature-settings. The font shorthand sets several at once, and @font-face loads custom web fonts.
The core properties
font-family: "Inter", system-ui, sans-serif;: a list; the browser uses the first available. Always end with a generic family.font-size: useremfor accessibility (respects user settings);clamp(1rem, 2.5vw, 1.5rem)for fluid type.font-weight:400normal,700bold, any value from 1 to 1000 with variable fonts.font-style:normal,italic,oblique 10deg.line-height: unitless, like1.5.font-variant-numeric: tabular-numsaligns numbers in tables and timers.- Shorthand:
font: italic 700 1.25rem/1.4 "Inter", sans-serif;(size and family are required).
Loading web fonts
@font-face {
font-family: "Inter";
src: url(/fonts/inter-var.woff2) format("woff2");
font-weight: 100 900;
font-display: swap;
}
- Use WOFF2 and variable fonts (one file, every weight).
font-display: swapshows fallback text immediately (no invisible text).- Preload the critical font file; subset it to the characters you need.
- Tune the fallback with
size-adjustto reduce layout shift (Next.jsnext/fontdoes this automatically).
System font stack
font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; costs zero bytes and looks native.
Code example
html
1<style>2 body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; max-width: 460px; }3 h1 { font: 800 clamp(1.5rem, 5vw, 2.5rem)/1.1 Georgia, "Times New Roman", serif; margin: 0 0 8px; }4 .lead { font-size: 1.125rem; font-style: italic; font-weight: 300; }5 .caps { font-variant: small-caps; letter-spacing: .05em; }6 .mono { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: .9rem; }7 table { font-variant-numeric: tabular-nums; }8 td { padding: 2px 10px; text-align: right; }9</style>10<h1>Typography matters</h1>11<p class="lead">Fluid headings, light italics and a system font stack.</p>12<p class="caps">Small caps for labels</p>13<p class="mono">const fast = "zero font bytes";</p>14<table>15 <tr><td>Lap 1</td><td>1:11.42</td></tr>16 <tr><td>Lap 2</td><td>1:09.87</td></tr>17</table>
Practice this question
Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the HTML & CSS set.