Skip to main content
← 🎨 CSS as a design systemΒ·Module B4 Β· Lesson 5
TaskDeclare 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.

Variable fonts: one file, infinite weights

100 XP7 min
Theory

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.

πŸ”’

Sign up to start coding

Theory is open to everyone. The interactive editor, live preview, and check are unlocked with a 7-day free trial β€” card required, cancel anytime.

Sign up β€” free trial β†’

First 10 lessons in each track are free. No card needed for those.

← PreviousNext lesson β†’

Get one Python or web tip a day β€” by email

Short, hand-written, no spam. Unsubscribe in one click.