Přejít k hlavnímu obsahu
← 🎨 CSS as a design system·Modul B4 · Lekce 5
ÚkolDeclare 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.

Variabilní písma: jeden soubor, nekonečné váhy

100 XP7 min
Teorie

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.

🔒

Zaregistruj se a začni programovat

Teorie je otevřená pro každého. Editor, živý náhled a check se odemknou s 7denní zkušební verzí zdarma — karta vyžadována, zrušíš kdykoli.

Registrace — zkušební verze zdarma →

Prvních 10 lekcí v každé trase je zdarma. Karta není potřeba.

← PředchozíDalší lekce →

Jeden tip k Pythonu nebo webu denně — e-mailem

Krátké, ručně psané, žádný spam. Odhlásit jedním klikem.