Naar hoofdinhoud
← 🎨 CSS as a design systemΒ·Module B4 Β· Les 5
OpdrachtDeclare a variable font-face for 'Inter' from /inter.woff2 (format 'woff2-variations'), font-weight range 100 900, font-display swap. Apply Inter to body. Set h1 font-weight to 800, body to 400.

Variabele lettertypen: één bestand, oneindige gewichten

100 XP7 min
Theorie

What changed in 2018

Before variable fonts, "Inter Regular," "Inter Medium," "Inter Bold" were THREE separate font files (~100KB each = 300KB to ship). Variable fonts pack all weights/widths/slants into ONE file (~150KB total). Less bandwidth, instant weight changes (e.g. on hover or animation).

@font-face {
  font-family: "Inter";
  src: url("/inter-variable.woff2") format("woff2-variations");
  font-weight: 100 900;       /* declare the available range */
  font-display: swap;
}

font-weight here is a RANGE β€” any value from 100 to 900 works:

body { font-weight: 400; }
h1 { font-weight: 800; }
button:hover { font-weight: 600; }    /* even non-standard weights work */

More axes than weight

Some variable fonts expose more dimensions:

  • font-weight (100-900)
  • font-stretch (50% condensed β†’ 200% extended)
  • font-style slant (-15Β° to 15Β°)
  • Custom axes via font-variation-settings:
.special {
  font-variation-settings:
    "wght" 650,         /* weight */
    "slnt" -5,          /* slant */
    "opsz" 14;          /* optical sizing */
}

Use the per-property shortcuts (font-weight) over font-variation-settings when you can β€” they animate cleaner and respect cascade.

File size comparison

FilesSize
Inter Regular + Medium + Semibold + Bold (4 files)~280KB
Inter Variable (1 file, all weights)~140KB

Half the bandwidth. Plus animate-able weight transitions.

πŸ”’

Registreer om te beginnen met coderen

Theorie is voor iedereen. De editor, live preview en check ontgrendelen met een 7-daagse gratis proefperiode β€” kaart vereist, opzegbaar.

Registreren β€” gratis proef β†’

De eerste 10 lessen in elke track zijn gratis. Geen kaart nodig.

← VorigeVolgende les β†’

EΓ©n Python- of web-tip per dag β€” per e-mail

Kort, met de hand geschreven, geen spam. Met één klik afmelden.